access to dynamic start-stop framework

Signed-off-by: zhangmingxiang <zhangmingxiang@huawei.com>
Change-Id: Id6d1a5241143582139db01292d6f6fb544ec6a10
Signed-off-by: zhangmingxiang <zhangmingxiang@huawei.com>
This commit is contained in:
zhangmingxiang 2023-02-27 12:00:38 +00:00
parent ba615fc753
commit 26404dc32b
88 changed files with 1146 additions and 1499 deletions

View File

@ -68,7 +68,6 @@
"//foundation/ability/dmsfwk/etc/init:etc",
"//foundation/ability/dmsfwk/etc/profile:distributedsched_trust",
"//foundation/ability/dmsfwk/sa_profile:dms_sa_profile",
"//foundation/ability/dmsfwk/services/base:dmsbaseinner",
"//foundation/ability/dmsfwk/services/dtbabilitymgr:distributed_ability_manager_svr",
"//foundation/ability/dmsfwk/services/dtbschedmgr:distributedschedsvr"
]
@ -93,14 +92,14 @@
"header_base": "//foundation/ability/dmsfwk/interfaces/innerkits/common/include",
"header_files": [
"distributed_ability_manager_client.h",
"distributed_ability_manager_proxy.h"
"distributed_ability_manager_proxy.h",
"dms_constant.h"
]
},
"name": "//foundation/ability/dmsfwk/interfaces/innerkits/common:common_sdk"
}
],
"test": [
"//foundation/ability/dmsfwk/services/base:unittest",
"//foundation/ability/dmsfwk/services/dtbschedmgr:unittest",
"//foundation/ability/dmsfwk/services/dtbabilitymgr:unittest",
"//foundation/ability/dmsfwk/test/fuzztest/continuationmanager_fuzzer:fuzztest"

View File

@ -3,16 +3,16 @@
"name" : "service:distributedsched",
"cmds" : [
"mkdir /data/service/el1/public/database 0711 ddms ddms",
"mkdir /data/service/el1/public/database/distributed_device_profile_service 02770 dms ddms",
"mkdir /data/service/el1/public/database/DistributedSchedule 02770 dms ddms"
]
}
],
"services" : [{
"name" : "distributedsched",
"path" : ["/system/bin/sa_main", "/system/profile/distributedsched.xml"],
"path" : ["/system/bin/sa_main", "/system/profile/distributedsched.json"],
"uid" : "dms",
"gid" : ["dms", "shell"],
"ondemand" : true,
"permission" : ["ohos.permission.DISTRIBUTED_DATASYNC", "ohos.permission.ACCESS_SERVICE_DM"],
"jobs" : {
"on-start" : "service:distributedsched"

View File

@ -1,7 +1,6 @@
{
"process": "distributedsched",
"said": [
1401,
6001
1401
]
}

View File

@ -1,4 +1,4 @@
# Copyright (c) 2022 Huawei Device Co., Ltd.
# Copyright (c) 2022-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
@ -17,8 +17,6 @@ config("common_public_config") {
visibility = [ ":*" ]
include_dirs = [
"include/",
"//foundation/ability/dmsfwk/interfaces/innerkits/continuation_manager/include/",
"//foundation/ability/dmsfwk/services/base/include",
"//foundation/ability/dmsfwk/services/dtbabilitymgr/include/",
"//foundation/ability/dmsfwk/utils/native/include/",
]

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Copyright (c) 2022-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
@ -37,7 +37,7 @@ public:
int32_t StartDeviceManager(
int32_t token, const std::shared_ptr<ContinuationExtraParams>& continuationExtraParams = nullptr);
private:
sptr<IDistributedAbilityManager> GetDmsProxy();
sptr<IDistributedAbilityManager> GetContinuationMgrService();
};
} // namespace DistributedSchedule
} // namespace OHOS

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* 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
@ -12,22 +12,16 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef OHOS_DISTRIBUTED_SCHED_INTERFACES_INNERKITS_DMS_DUMPER_H
#define OHOS_DISTRIBUTED_SCHED_INTERFACES_INNERKITS_DMS_DUMPER_H
#include <string>
#include <vector>
#include "refbase.h"
#ifndef OHOS_DISTRIBUTED_DMS_CONSTANT_H
#define OHOS_DISTRIBUTED_DMS_CONSTANT_H
namespace OHOS {
namespace DistributedSchedule {
class DmsDumper : public virtual RefBase {
public:
DmsDumper() = default;
virtual ~DmsDumper() = default;
virtual bool ProcessDistributedSchedDump(const std::vector<std::string>& args, std::string& result) = 0;
};
} // namespace DistributedSchedule
} // namespace OHOS
#endif // OHOS_DISTRIBUTED_SCHED_INTERFACES_INNERKITS_DMS_DUMPER_H
namespace Constants {
constexpr const char* DMS_NAME = "dmsfwk";
constexpr const char* DMS_VERSION = "4.0.0";
} // Constants
} // DistributedSchedule
} // OHOS
#endif

View File

@ -1,4 +1,4 @@
# Copyright (c) 2022 Huawei Device Co., Ltd.
# Copyright (c) 2022-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
@ -17,7 +17,7 @@ config("continuation_manager_public_config") {
visibility = [ ":*" ]
include_dirs = [
"include/",
"//foundation/ability/dmsfwk/services/base/include",
"//foundation/ability/dmsfwk/services/dtbabilitymgr/include/",
]
cflags = []

View File

@ -1,4 +1,4 @@
# Copyright (c) 2022 Huawei Device Co., Ltd.
# Copyright (c) 2022-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
@ -16,8 +16,8 @@ import("//build/ohos.gni")
config("continuationmanager_napi_public_config") {
visibility = [ ":*" ]
include_dirs = [
"//foundation/ability/dmsfwk/interfaces/kits/napi/include",
"//foundation/ability/dmsfwk/services/base/include",
"//foundation/ability/dmsfwk/interfaces/kits/napi/include/",
"//foundation/ability/dmsfwk/services/dtbabilitymgr/include/",
]
cflags = []

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Copyright (c) 2022-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
@ -17,9 +17,9 @@
#include <memory>
#include "base/continuationmgr_log.h"
#include "device_connect_status.h"
#include "distributed_ability_manager_client.h"
#include "dtbschedmgr_log.h"
#include "js_runtime_utils.h"
#include "napi_common_util.h"
#include "napi_error_code.h"

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Copyright (c) 2022-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
@ -15,7 +15,7 @@
#include "js_device_selection_listener.h"
#include "dtbschedmgr_log.h"
#include "base/continuationmgr_log.h"
#include "js_runtime_utils.h"
#include "napi_common_util.h"

28
sa_profile/1401.json Normal file
View File

@ -0,0 +1,28 @@
{
"process": "distributedsched",
"systemability": [
{
"name": 1401,
"libpath": "libdistributedschedsvr.z.so",
"run-on-create": false,
"distributed": true,
"dump-level": 1,
"start-on-demand": {
"deviceonline": [
{
"name": "deviceonline",
"value": "on"
}
]
},
"stop-on-demand": {
"deviceonline": [
{
"name": "deviceonline",
"value": "off"
}
]
}
}
]
}

View File

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<!--Copyright (c) 2021 Huawei Device Co., Ltd.
<!--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
@ -13,11 +13,11 @@
limitations under the License.
-->
<info>
<process>distributedsched</process>
<process>foundation</process>
<systemability> <!--Declare a system ability and its profile-->
<name>1401</name> <!--Declare the name of system ability-->
<name>1404</name> <!--Declare the name of system ability-->
<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. -->
<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.-->
<distributed>false</distributed> <!-- "true" means the system ability supports distributed scheduling while "false" is not.-->
</systemability>
</info>

View File

@ -1,4 +1,4 @@
# Copyright (c) 2021 Huawei Device Co., Ltd.
# Copyright (c) 2021-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
@ -14,6 +14,9 @@
import("//build/ohos/sa_profile/sa_profile.gni")
ohos_sa_profile("dms_sa_profile") {
sources = [ "1401.xml" ]
sources = [
"1401.json",
"1404.xml",
]
part_name = "dmsfwk"
}

View File

@ -1,61 +0,0 @@
# 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")
group("unittest") {
testonly = true
deps = [ "test:unittest" ]
}
config("distributed_sched_config") {
visibility = [ ":*" ]
include_dirs = [
"include/",
"//foundation/ability/dmsfwk/interfaces/innerkits/continuation_manager/include/",
]
}
ohos_shared_library("dmsbaseinner") {
install_enable = true
sources = [
"src/adapter/dnetwork_adapter.cpp",
"src/deviceManager/dms_device_info.cpp",
"src/dfx/dms_hisysevent_report.cpp",
"src/dfx/dms_hitrace_chain.cpp",
"src/distributed_device_node_listener.cpp",
"src/dms_version_manager.cpp",
"src/dtbschedmgr_device_info_storage.cpp",
]
public_configs = [
":distributed_sched_config",
"//foundation/ability/dmsfwk/services/dtbschedmgr/test/resource:coverage_flags",
]
external_deps = [
"c_utils:utils",
"device_info_manager:distributed_device_profile_client",
"device_manager:devicemanagersdk",
"dsoftbus:softbus_client",
"eventhandler:libeventhandler",
"hisysevent_native:libhisysevent",
"hitrace_native:libhitracechain",
"hiviewdfx_hilog_native:libhilog",
"ipc:ipc_core",
"safwk:system_ability_fwk",
"samgr:samgr_proxy",
]
part_name = "dmsfwk"
subsystem_name = "ability"
}

View File

@ -1,42 +0,0 @@
/*
* 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_SCHED_INTERFACES_INNERKITS_DMS_NOTIFIER_H
#define OHOS_DISTRIBUTED_SCHED_INTERFACES_INNERKITS_DMS_NOTIFIER_H
#include <string>
#include "continuation_extra_params.h"
#include "continuation_result.h"
#include "iremote_object.h"
namespace OHOS {
namespace DistributedSchedule {
class DmsNotifier : public virtual RefBase {
public:
DmsNotifier() = default;
virtual ~DmsNotifier() = default;
virtual void DeviceOnlineNotify(const std::string& deviceId) = 0;
virtual void DeviceOfflineNotify(const std::string& deviceId) = 0;
virtual void ProcessNotifierDied(const sptr<IRemoteObject>& notifier) = 0;
virtual void ScheduleStartDeviceManager(const sptr<IRemoteObject>& appProxy, int32_t token,
const std::shared_ptr<ContinuationExtraParams>& continuationExtraParams = nullptr) = 0;
virtual int32_t OnDeviceConnect(int32_t token, const std::vector<ContinuationResult>& continuationResults) = 0;
virtual int32_t OnDeviceDisconnect(int32_t token, const std::vector<ContinuationResult>& continuationResults) = 0;
virtual int32_t OnDeviceCancel() = 0;
};
} // namespace DistributedSchedule
} // namespace OHOS
#endif // OHOS_DISTRIBUTED_SCHED_INTERFACES_INNERKITS_DMS_NOTIFIER_H

View File

@ -1,74 +0,0 @@
# 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")
import("//build/test.gni")
import("//foundation/ability/dmsfwk/dmsfwk.gni")
module_output_path = "dmsfwk/distributed_base_svr_test"
distributed_service = "//foundation/ability/dmsfwk/services"
base_configs = [ "${distributed_service}/base:distributed_sched_config" ]
config("test_config") {
visibility = [ ":*" ]
include_dirs = [ "//foundation/ability/dmsfwk/utils/native/include" ]
}
base_external_deps = [
"c_utils:utils",
"device_manager:devicemanagersdk",
"eventhandler:libeventhandler",
"hiviewdfx_hilog_native:libhilog",
"init:libbegetutil",
"ipc:ipc_core",
"safwk:system_ability_fwk",
"samgr:samgr_proxy",
]
base_public_deps = [
"//foundation/ability/dmsfwk/services/base:dmsbaseinner",
"//third_party/googletest:gmock_main",
"//third_party/googletest:gtest_main",
"//third_party/libxml2:libxml2",
]
ohos_unittest("dmsbasetest") {
module_out_path = module_output_path
sources = [
"${distributed_service}/base/src/adapter/dnetwork_adapter.cpp",
"${distributed_service}/base/src/deviceManager/dms_device_info.cpp",
"${distributed_service}/base/src/distributed_device_node_listener.cpp",
"${distributed_service}/base/src/dtbschedmgr_device_info_storage.cpp",
"unittest/deviceManager/dms_device_info_test.cpp",
"unittest/dfx/dms_hisysevent_report_test.cpp",
"unittest/dms_network_adapter_test.cpp",
"unittest/dtbschedmgr_device_info_storage_test.cpp",
]
configs = [
":test_config",
"//foundation/ability/dmsfwk/services/dtbschedmgr/test/resource:coverage_flags",
]
configs += base_configs
external_deps = base_external_deps
public_deps = base_public_deps
part_name = "dmsfwk"
subsystem_name = "ability"
}
group("unittest") {
testonly = true
deps = [ ":dmsbasetest" ]
}

View File

@ -1,4 +1,4 @@
# Copyright (c) 2022 Huawei Device Co., Ltd.
# Copyright (c) 2022-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
@ -21,16 +21,13 @@ group("unittest") {
config("distributed_ability_manager_config") {
visibility = [ ":*" ]
include_dirs = [
"include/",
"//foundation/ability/dmsfwk/interfaces/innerkits/common/include/",
"//foundation/ability/dmsfwk/interfaces/innerkits/continuation_manager/include/",
]
include_dirs = [ "include/" ]
}
ohos_shared_library("distributed_ability_manager_svr") {
install_enable = true
sources = [
"src/continuation_manager/app_connection_stub.cpp",
"src/continuation_manager/app_device_callback_stub.cpp",
"src/continuation_manager/connect_status_info.cpp",
"src/continuation_manager/continuation_extra_params.cpp",
@ -52,18 +49,23 @@ ohos_shared_library("distributed_ability_manager_svr") {
ldflags = [ "-rdynamic" ]
external_deps = [
"ability_base:want",
"ability_runtime:ability_manager",
"access_token:libaccesstoken_sdk",
"bundle_framework:appexecfwk_base",
"bundle_framework:appexecfwk_core",
"c_utils:utils",
"device_manager:devicemanagersdk",
"dmsfwk:common_sdk",
"dmsfwk:continuation_manager",
"eventhandler:libeventhandler",
"hiviewdfx_hilog_native:libhilog",
"init:libbegetutil",
"ipc:ipc_core",
"os_account:os_account_innerkits",
"safwk:system_ability_fwk",
"samgr:samgr_proxy",
]
deps = [ "//foundation/ability/dmsfwk/services/base:dmsbaseinner" ]
part_name = "dmsfwk"
subsystem_name = "ability"
}

View File

@ -0,0 +1,120 @@
/*
* 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 CONTINUATION_MANAGER_LOG_H_
#define CONTINUATION_MANAGER_LOG_H_
#include "errors.h"
#include "hilog/log_c.h"
#include "hilog/log_cpp.h"
#include "inttypes.h"
namespace OHOS {
namespace DistributedSchedule {
static constexpr OHOS::HiviewDFX::HiLogLabel CONTINUATION_MANAGER_LABEL = {LOG_CORE, 0xD001800,
"ContinuationMgrService"};
#ifdef HILOGD
#undef HILOGD
#endif
#ifdef HILOGF
#undef HILOGF
#endif
#ifdef HILOGE
#undef HILOGE
#endif
#ifdef HILOGW
#undef HILOGW
#endif
#ifdef HILOGI
#undef HILOGI
#endif
#define DMS_LOG(level, fmt, ...) HiviewDFX::HiLog::level(CONTINUATION_MANAGER_LABEL, \
"%{public}s::%{public}s " fmt, TAG.c_str(), __FUNCTION__, ##__VA_ARGS__)
#define HILOGF(fmt, ...) DMS_LOG(Fatal, fmt, ##__VA_ARGS__)
#define HILOGE(fmt, ...) DMS_LOG(Error, fmt, ##__VA_ARGS__)
#define HILOGW(fmt, ...) DMS_LOG(Warn, fmt, ##__VA_ARGS__)
#define HILOGI(fmt, ...) DMS_LOG(Info, fmt, ##__VA_ARGS__)
#define HILOGD(fmt, ...) DMS_LOG(Debug, fmt, ##__VA_ARGS__)
enum {
/**
* Module type: Distributed schedule Service side
*/
DMS_MODULE_TYPE_SERVICE = 0,
};
// offset of dms error, only be used in this file.
constexpr ErrCode DMS_SERVICE_ERR_OFFSET = ErrCodeOffset(SUBSYS_DISTRIBUTEDSCHEDULE, DMS_MODULE_TYPE_SERVICE);
enum {
/**
* Result(29360128) for invalid parameters.
*/
INVALID_PARAMETERS_ERR = DMS_SERVICE_ERR_OFFSET,
/**
* Result(29360141) for dump write file error.
*/
DMS_WRITE_FILE_FAILED_ERR = 29360141,
/**
* Result(29360157) for permission denied.
*/
DMS_PERMISSION_DENIED = 29360157,
/*
* Result(29360207) for app registered exceed max times.
*/
REGISTER_EXCEED_MAX_TIMES = 29360207,
/*
* Result(29360208) for token has not registered.
*/
TOKEN_HAS_NOT_REGISTERED = 29360208,
/*
* Result(29360209) for callback has registered.
*/
CALLBACK_HAS_REGISTERED = 29360209,
/*
* Result(29360210) for callback has not registered.
*/
CALLBACK_HAS_NOT_REGISTERED = 29360210,
/*
* Result(29360211) for connect ability failed.
*/
CONNECT_ABILITY_FAILED = 29360211,
/*
* Result(29360212) for disconnect ability failed.
*/
DISCONNECT_ABILITY_FAILED = 29360212,
/*
* Result(29360214) for unknown callback type.
*/
UNKNOWN_CALLBACK_TYPE = 29360214,
/*
* Result(29360215) for invalid connect status.
*/
INVALID_CONNECT_STATUS = 29360215,
/*
* Result(29360216) for invalid continuation mode.
*/
INVALID_CONTINUATION_MODE = 29360216,
};
} // namespace DistributedSchedule
} // namespace OHOS
#endif // CONTINUATION_MANAGER_LOG_H_

View File

@ -0,0 +1,113 @@
/*
* 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 CONTINUATION_MANAGER_PARCEL_HELPER_H
#define CONTINUATION_MANAGER_PARCEL_HELPER_H
#include <cinttypes>
#include "base/continuationmgr_log.h"
namespace OHOS {
namespace DistributedSchedule {
#define PARCEL_WRITE_HELPER(parcel, type, value) \
do { \
bool ret = parcel.Write##type((value)); \
if (!ret) { \
HILOGE("%{public}s write value failed!", __func__); \
return ERR_FLATTEN_OBJECT; \
} \
} while (0)
#define PARCEL_WRITE_HELPER_NORET(parcel, type, value) \
do { \
bool ret = parcel.Write##type((value)); \
if (!ret) { \
HILOGE("%{public}s write value failed!", __func__); \
return; \
} \
} while (0)
#define PARCEL_WRITE_HELPER_RET(parcel, type, value, failRet) \
do { \
bool ret = parcel.Write##type((value)); \
if (!ret) { \
HILOGE("%{public}s write value failed!", __func__); \
return failRet; \
} \
} while (0)
#define PARCEL_READ_HELPER(parcel, type, out) \
do { \
bool ret = parcel.Read##type((out)); \
if (!ret) { \
HILOGE("%{public}s read value failed!", __func__); \
return ERR_FLATTEN_OBJECT; \
} \
} while (0)
#define PARCEL_READ_HELPER_RET(parcel, type, out, failRet) \
do { \
bool ret = parcel.Read##type((out)); \
if (!ret) { \
HILOGE("%{public}s read value failed!", __func__); \
return failRet; \
} \
} while (0)
#define PARCEL_READ_HELPER_NORET(parcel, type, out) \
do { \
bool ret = parcel.Read##type((out)); \
if (!ret) { \
HILOGW("%{public}s read value failed!", __func__); \
} \
} while (0)
#define PARCEL_TRANSACT_SYNC_RET_INT(remote, code, data, reply) \
do { \
MessageOption option; \
int32_t error = remote->SendRequest(code, data, reply, option); \
if (error != ERR_NONE) { \
HILOGE("%{public}s transact failed, error: %{public}d", __func__, error); \
return error; \
} \
int32_t result = reply.ReadInt32(); \
HILOGD("%{public}s get result from server data = %{public}d", __func__, result); \
return result; \
} while (0)
#define PARCEL_TRANSACT_SYNC_NORET(remote, code, data, reply) \
do { \
MessageOption option; \
int32_t error = remote->SendRequest(code, data, reply, option); \
if (error != ERR_NONE) { \
HILOGE("%{public}s transact failed, error: %{public}d", __func__, error); \
return; \
} \
HILOGD("%{public}s transact success!", __func__); \
} while (0)
#define PARCEL_WRITE_REPLY_NOERROR(reply, type, result) \
do { \
bool ret = reply.Write##type(result); \
if (!ret) { \
HILOGW("%{public}s write reply failed.", __func__); \
} \
return ERR_NONE; \
} while (0)
} // namespace DistributedSchedule
} // namespace OHOS
#endif /* CONTINUATION_MANAGER_PARCEL_HELPER_H */

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Copyright (c) 2022-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
@ -19,7 +19,6 @@
#include "ability_connect_callback_interface.h"
#include "continuation_extra_params.h"
#include "dms_notifier.h"
#include "message_parcel.h"
#include "nocopyable.h"
#include "iremote_object.h"
@ -29,7 +28,7 @@ namespace OHOS {
namespace DistributedSchedule {
class AppConnectionStub : public IRemoteStub<AAFwk::IAbilityConnection> {
public:
AppConnectionStub(const sptr<DmsNotifier>& dmsNotifier, int32_t token,
explicit AppConnectionStub(int32_t token,
const std::shared_ptr<ContinuationExtraParams>& continuationExtraParams = nullptr);
virtual ~AppConnectionStub() = default;
@ -42,7 +41,6 @@ public:
private:
DISALLOW_COPY_AND_MOVE(AppConnectionStub);
sptr<DmsNotifier> dmsNotifier_;
int32_t token_;
std::shared_ptr<ContinuationExtraParams> continuationExtraParams_;
};

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Copyright (c) 2022-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
@ -19,9 +19,8 @@
#include <iosfwd>
#include <vector>
#include "continuation_result.h"
#include "dms_notifier.h"
#include "app_device_callback_interface.h"
#include "continuation_result.h"
#include "iremote_stub.h"
#include "message_option.h"
#include "message_parcel.h"
@ -32,7 +31,7 @@ namespace OHOS {
namespace DistributedSchedule {
class AppDeviceCallbackStub : public IRemoteStub<AppDeviceCallbackInterface> {
public:
explicit AppDeviceCallbackStub(const sptr<DmsNotifier>& dmsNotifier);
AppDeviceCallbackStub() = default;
virtual ~AppDeviceCallbackStub() = default;
virtual int32_t OnRemoteRequest(uint32_t code, MessageParcel& data,
@ -43,8 +42,6 @@ private:
int32_t OnDeviceConnect(int32_t token, const std::vector<ContinuationResult>& continuationResults) override;
int32_t OnDeviceDisconnect(int32_t token, const std::vector<ContinuationResult>& continuationResults) override;
int32_t OnDeviceCancel() override;
sptr<DmsNotifier> dmsNotifier_;
};
} // namespace DistributedSchedule
} // namespace OHOS

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Copyright (c) 2022-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
@ -16,7 +16,6 @@
#ifndef OHOS_DISTRIBUTED_ABILITY_MANAGER_NOTIFIER_DEATH_RECIPIENT_H
#define OHOS_DISTRIBUTED_ABILITY_MANAGER_NOTIFIER_DEATH_RECIPIENT_H
#include "dms_notifier.h"
#include "iremote_object.h"
#include "refbase.h"
@ -24,13 +23,10 @@ namespace OHOS {
namespace DistributedSchedule {
class NotifierDeathRecipient : public IRemoteObject::DeathRecipient {
public:
explicit NotifierDeathRecipient(const sptr<DmsNotifier>& dmsNotifier);
~NotifierDeathRecipient() override = default;
NotifierDeathRecipient() = default;
virtual ~NotifierDeathRecipient() = default;
void OnRemoteDied(const wptr<IRemoteObject>& remote) override;
private:
sptr<DmsNotifier> dmsNotifier_;
};
} // namespace DistributedSchedule
} // namespace OHOS

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Copyright (c) 2022-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
@ -19,22 +19,20 @@
#include <string>
#include <vector>
#include "dms_dumper.h"
namespace OHOS {
namespace DistributedSchedule {
class DistributedAbilityManagerDumper {
public:
static bool Dump(const sptr<DmsDumper>& dmsDumper, const std::vector<std::string>& args, std::string& result);
static bool Dump(const std::vector<std::string>& args, std::string& result);
private:
DistributedAbilityManagerDumper() = default;
~DistributedAbilityManagerDumper() = default;
static bool CanDump();
static bool DumpDefault(std::string& result);
static void ShowAppRegisterInfo(std::string& result);
static void ShowHelp(std::string& result);
static void IllegalInput(std::string& result);
static bool CanDump();
static bool ProcessDistributedSchedDump(const sptr<DmsDumper>& dmsDumper,
const std::vector<std::string>& args, std::string& result);
};
} // namespace DistributedSchedule
} // namespace OHOS

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Copyright (c) 2022-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
@ -26,9 +26,6 @@ namespace DistributedSchedule {
namespace {
constexpr int32_t VALUE_NULL = -1; // no object in parcel
constexpr int32_t VALUE_OBJECT = 1; // object exist in parcel
constexpr const char* DMS_NAME = "dmsfwk";
constexpr const char* DMS_VERSION = "3.2.0";
}
class IDistributedAbilityManager : public OHOS::IRemoteBroker {
public:

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Copyright (c) 2022-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
@ -16,36 +16,25 @@
#ifndef OHOS_DISTRIBUTED_ABILITY_MANAGER_SERVICE_H
#define OHOS_DISTRIBUTED_ABILITY_MANAGER_SERVICE_H
#include "bundlemgr/bundle_mgr_interface.h"
#include "bundlemgr/bundle_mgr_proxy.h"
#include "continuation_manager/notifier_info.h"
#include "distributed_ability_manager_stub.h"
#include "dms_dumper.h"
#include "dms_notifier.h"
#include "event_handler.h"
#include "single_instance.h"
#include "system_ability.h"
namespace OHOS {
namespace DistributedSchedule {
class DistributedAbilityManagerService : public SystemAbility, public DistributedAbilityManagerStub,
public DmsNotifier, public DmsDumper {
class DistributedAbilityManagerService : public SystemAbility, public DistributedAbilityManagerStub {
DECLARE_SYSTEM_ABILITY(DistributedAbilityManagerService);
DECLARE_SINGLE_INSTANCE_BASE(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;
bool IsDistributedSchedLoaded() override;
void DeviceOnlineNotify(const std::string& deviceId) override;
void DeviceOfflineNotify(const std::string& deviceId) override;
void ProcessNotifierDied(const sptr<IRemoteObject>& notifier) override;
void ScheduleStartDeviceManager(const sptr<IRemoteObject>& appProxy, int32_t token,
const std::shared_ptr<ContinuationExtraParams>& continuationExtraParams = nullptr) override;
int32_t OnDeviceConnect(int32_t token, const std::vector<ContinuationResult>& continuationResults) override;
int32_t OnDeviceDisconnect(int32_t token, const std::vector<ContinuationResult>& continuationResults) override;
int32_t OnDeviceCancel() override;
int32_t Dump(int32_t fd, const std::vector<std::u16string>& args) override;
int32_t Register(
const std::shared_ptr<ContinuationExtraParams>& continuationExtraParams, int32_t& token) override;
@ -57,9 +46,16 @@ public:
const DeviceConnectStatus& deviceConnectStatus) override;
int32_t StartDeviceManager(
int32_t token, const std::shared_ptr<ContinuationExtraParams>& continuationExtraParams = nullptr) override;
int32_t Dump(int32_t fd, const std::vector<std::u16string>& args) override;
bool ProcessDistributedSchedDump(const std::vector<std::string>& args, std::string& result) override;
void ProcessNotifierDied(const sptr<IRemoteObject>& notifier);
void ScheduleStartDeviceManager(const sptr<IRemoteObject>& appProxy, int32_t token,
const std::shared_ptr<ContinuationExtraParams>& continuationExtraParams = nullptr);
int32_t OnDeviceConnect(int32_t token, const std::vector<ContinuationResult>& continuationResults);
int32_t OnDeviceDisconnect(int32_t token, const std::vector<ContinuationResult>& continuationResults);
int32_t OnDeviceCancel();
void DumpAppRegisterInfo(std::string& info);
private:
DistributedAbilityManagerService();
bool IsExceededRegisterMaxNum(uint32_t accessToken);
bool IsContinuationModeValid(ContinuationMode continuationMode);
bool IsConnectStatusValid(DeviceConnectStatus deviceConnectStatus);
@ -71,39 +67,18 @@ private:
const std::vector<ContinuationResult>& continuationResults);
bool HandleDeviceDisconnect(const sptr<IRemoteObject>& notifier,
const std::vector<ContinuationResult>& continuationResults);
int32_t ConnectAbility(const sptr<DmsNotifier>& dmsNotifier, int32_t token,
const std::shared_ptr<ContinuationExtraParams>& continuationExtraParams);
int32_t ConnectAbility(int32_t token, const std::shared_ptr<ContinuationExtraParams>& continuationExtraParams);
int32_t DisconnectAbility();
bool QueryExtensionAbilityInfo(const std::vector<int32_t>& ids, const AAFwk::Want& want,
AppExecFwk::ExtensionAbilityInfo& extensionInfo);
bool HandleDisconnectAbility();
void HandleNotifierDied(const sptr<IRemoteObject>& notifier);
void HandleStartDeviceManager(int32_t token,
const std::shared_ptr<ContinuationExtraParams>& continuationExtraParams = nullptr);
void HandleUpdateConnectStatus(int32_t token, std::string deviceId,
const DeviceConnectStatus& deviceConnectStatus);
void DumpNotifierLocked(const std::vector<int32_t>& tokenVec, std::string& info);
bool InitDmsImplFunc();
using LibHandle = void*;
LibHandle dmsImplHandle_ = nullptr;
bool InitFunc();
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);
using ConnectAbilityFunc = int32_t(*)(const sptr<DmsNotifier>& dmsNotifier, int32_t token,
const std::shared_ptr<ContinuationExtraParams>& continuationExtraParams);
using DisconnectAbilityFunc = int32_t(*)();
using DistributedSchedDumpFunc = bool(*)(const std::vector<std::string>& args, std::string& result);
OnRemoteRequestFunc onRemoteRequestFunc_ = nullptr;
DeviceOnlineNotifyFunc deviceOnlineNotifyFunc_ = nullptr;
DeviceOfflineNotifyFunc deviceOfflineNotifyFunc_ = nullptr;
ConnectAbilityFunc connectAbilityFunc_ = nullptr;
DisconnectAbilityFunc disconnectAbilityFunc_ = nullptr;
DistributedSchedDumpFunc distributedSchedDumpFunc_ = nullptr;
std::atomic_bool isLoaded_ = false;
std::mutex libLoadLock_;
std::mutex tokenMutex_;
std::atomic<int32_t> token_ {0};
std::mutex tokenMapMutex_;
@ -111,6 +86,7 @@ private:
std::mutex callbackMapMutex_;
std::map<int32_t, std::unique_ptr<NotifierInfo>> callbackMap_;
sptr<IRemoteObject::DeathRecipient> notifierDeathRecipient_;
sptr<IRemoteObject> connect_;
std::mutex appProxyMutex_;
sptr<IRemoteObject> appProxy_;
std::shared_ptr<AppExecFwk::EventHandler> continuationHandler_;

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Copyright (c) 2022-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
@ -34,15 +34,6 @@ public:
~DistributedAbilityManagerStub();
int32_t OnRemoteRequest(uint32_t code, MessageParcel& data,
MessageParcel& reply, MessageOption& option) override;
virtual int32_t SendRequestToImpl(uint32_t code, MessageParcel& data, MessageParcel& reply,
MessageOption& option)
{
return ERR_NONE;
}
virtual bool IsDistributedSchedLoaded()
{
return false;
}
private:
bool EnforceInterfaceToken(MessageParcel& data);
@ -53,14 +44,10 @@ private:
int32_t UnregisterDeviceSelectionCallbackInner(MessageParcel& data, MessageParcel& reply);
int32_t UpdateConnectStatusInner(MessageParcel& data, MessageParcel& reply);
int32_t StartDeviceManagerInner(MessageParcel& data, MessageParcel& reply);
int32_t GetDistributedComponentListInner(MessageParcel& data, MessageParcel& reply, MessageOption& option);
bool VerifyPermission(uint32_t accessToken, const std::string& permissionName) const;
using Func = int32_t(DistributedAbilityManagerStub::*)(MessageParcel& data, MessageParcel& reply);
std::map<uint32_t, Func> funcsMap_;
using distributedFunc = int32_t(DistributedAbilityManagerStub::*)(MessageParcel& data,
MessageParcel& reply, MessageOption& option);
std::map<uint32_t, distributedFunc> distributedFuncMap_;
};
} // namespace DistributedSchedule
} // namespace OHOS

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Copyright (c) 2022-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
@ -13,9 +13,10 @@
* limitations under the License.
*/
#include "app_connection_stub.h"
#include "continuation_manager/app_connection_stub.h"
#include "dtbschedmgr_log.h"
#include "base/continuationmgr_log.h"
#include "distributed_ability_manager_service.h"
#include "ipc_types.h"
namespace OHOS {
@ -25,10 +26,9 @@ namespace {
const std::string TAG = "AppConnectionStub";
}
AppConnectionStub::AppConnectionStub(const sptr<DmsNotifier>& dmsNotifier, int32_t token,
AppConnectionStub::AppConnectionStub(int32_t token,
const std::shared_ptr<ContinuationExtraParams>& continuationExtraParams)
{
dmsNotifier_ = dmsNotifier;
token_ = token;
continuationExtraParams_ = continuationExtraParams;
}
@ -76,22 +76,16 @@ void AppConnectionStub::OnAbilityConnectDone(const AppExecFwk::ElementName& elem
const sptr<IRemoteObject>& remoteObject, int32_t resultCode)
{
HILOGD("called.");
if (dmsNotifier_ == nullptr) {
HILOGE("dmsNotifier_ is nullptr");
return;
}
dmsNotifier_->ScheduleStartDeviceManager(remoteObject, token_, continuationExtraParams_);
DistributedAbilityManagerService::GetInstance().ScheduleStartDeviceManager(remoteObject,
token_, continuationExtraParams_);
}
void AppConnectionStub::OnAbilityDisconnectDone(const AppExecFwk::ElementName& element,
int32_t resultCode)
{
HILOGD("called.");
if (dmsNotifier_ == nullptr) {
HILOGE("dmsNotifier_ is nullptr");
return;
}
dmsNotifier_->ScheduleStartDeviceManager(nullptr, token_, continuationExtraParams_);
DistributedAbilityManagerService::GetInstance().ScheduleStartDeviceManager(nullptr,
token_, continuationExtraParams_);
}
} // namespace DistributedSchedule
} // namespace OHOS

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Copyright (c) 2022-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
@ -17,11 +17,11 @@
#include <string>
#include "continuation_extra_params.h"
#include "dtbschedmgr_log.h"
#include "base/continuationmgr_log.h"
#include "base/parcel_helper.h"
#include "distributed_ability_manager_service.h"
#include "ipc_object_stub.h"
#include "ipc_types.h"
#include "parcel_helper.h"
namespace OHOS {
namespace DistributedSchedule {
@ -29,11 +29,6 @@ namespace {
const std::string TAG = "AppDeviceCallbackStub";
}
AppDeviceCallbackStub::AppDeviceCallbackStub(const sptr<DmsNotifier>& dmsNotifier)
{
dmsNotifier_ = dmsNotifier;
}
int32_t AppDeviceCallbackStub::OnRemoteRequest(uint32_t code, MessageParcel& data,
MessageParcel& reply, MessageOption& option)
{
@ -79,35 +74,20 @@ int32_t AppDeviceCallbackStub::OnDeviceConnect(int32_t token,
const std::vector<ContinuationResult>& continuationResults)
{
HILOGD("called.");
if (dmsNotifier_ == nullptr) {
HILOGE("dmsNotifier_ is nullptr");
return ERR_NULL_OBJECT;
}
int32_t result = dmsNotifier_->OnDeviceConnect(token, continuationResults);
return result;
return DistributedAbilityManagerService::GetInstance().OnDeviceConnect(token, continuationResults);
}
int32_t AppDeviceCallbackStub::OnDeviceDisconnect(int32_t token,
const std::vector<ContinuationResult>& continuationResults)
{
HILOGD("called.");
if (dmsNotifier_ == nullptr) {
HILOGE("dmsNotifier_ is nullptr");
return ERR_NULL_OBJECT;
}
int32_t result = dmsNotifier_->OnDeviceDisconnect(token, continuationResults);
return result;
return DistributedAbilityManagerService::GetInstance().OnDeviceDisconnect(token, continuationResults);
}
int32_t AppDeviceCallbackStub::OnDeviceCancel()
{
HILOGD("called.");
if (dmsNotifier_ == nullptr) {
HILOGE("dmsNotifier_ is nullptr");
return ERR_NULL_OBJECT;
}
int32_t result = dmsNotifier_->OnDeviceCancel();
return result;
return DistributedAbilityManagerService::GetInstance().OnDeviceCancel();
}
} // namespace DistributedSchedule
} // namespace OHOS

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Copyright (c) 2022-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
@ -18,7 +18,7 @@
#include <iosfwd>
#include <new>
#include "dtbschedmgr_log.h"
#include "base/continuationmgr_log.h"
namespace OHOS {
namespace DistributedSchedule {

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Copyright (c) 2022-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
@ -20,7 +20,7 @@
#include <new>
#include <vector>
#include "dtbschedmgr_log.h"
#include "base/continuationmgr_log.h"
#include "string_ex.h"
namespace OHOS {

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Copyright (c) 2022-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
@ -17,12 +17,12 @@
#include <string>
#include "base/continuationmgr_log.h"
#include "base/parcel_helper.h"
#include "continuation_result.h"
#include "dtbschedmgr_log.h"
#include "iremote_object.h"
#include "message_option.h"
#include "message_parcel.h"
#include "parcel_helper.h"
namespace OHOS {
namespace DistributedSchedule {

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Copyright (c) 2022-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
@ -19,11 +19,11 @@
#include <string>
#include <vector>
#include "dtbschedmgr_log.h"
#include "base/continuationmgr_log.h"
#include "base/parcel_helper.h"
#include "errors.h"
#include "ipc_object_stub.h"
#include "ipc_types.h"
#include "parcel_helper.h"
namespace OHOS {
namespace DistributedSchedule {

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Copyright (c) 2022-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
@ -18,7 +18,8 @@
#include <iosfwd>
#include <string>
#include "dtbschedmgr_log.h"
#include "base/continuationmgr_log.h"
#include "distributed_ability_manager_service.h"
namespace OHOS {
namespace DistributedSchedule {
@ -26,19 +27,10 @@ namespace {
const std::string TAG = "NotifierDeathRecipient";
}
NotifierDeathRecipient::NotifierDeathRecipient(const sptr<DmsNotifier>& dmsNotifier)
{
dmsNotifier_ = dmsNotifier;
}
void NotifierDeathRecipient::OnRemoteDied(const wptr<IRemoteObject>& remote)
{
HILOGD("called");
if (dmsNotifier_ == nullptr) {
HILOGE("dmsNotifier_ is nullptr");
return;
}
dmsNotifier_->ProcessNotifierDied(remote.promote());
DistributedAbilityManagerService::GetInstance().ProcessNotifierDied(remote.promote());
}
} // namespace DistributedSchedule
} // namespace OHOS

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Copyright (c) 2022-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
@ -14,8 +14,8 @@
*/
#include "distributed_ability_manager_client.h"
#include "base/continuationmgr_log.h"
#include "distributed_ability_manager_proxy.h"
#include "dtbschedmgr_log.h"
#include "if_system_ability_manager.h"
#include "ipc_skeleton.h"
#include "iservice_registry.h"
@ -24,21 +24,21 @@
namespace OHOS {
namespace DistributedSchedule {
namespace {
const std::string TAG = "DistributedAbilityManagerClient";
const std::string TAG = "ContinuationManagerClient";
}
IMPLEMENT_SINGLE_INSTANCE(DistributedAbilityManagerClient);
sptr<IDistributedAbilityManager> DistributedAbilityManagerClient::GetDmsProxy()
sptr<IDistributedAbilityManager> DistributedAbilityManagerClient::GetContinuationMgrService()
{
auto samgrProxy = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
if (samgrProxy == nullptr) {
HILOGE("get samgr failed.");
return nullptr;
}
sptr<IRemoteObject> remoteObj = samgrProxy->GetSystemAbility(DISTRIBUTED_SCHED_SA_ID);
sptr<IRemoteObject> remoteObj = samgrProxy->GetSystemAbility(CONTINUATION_MANAGER_SA_ID);
if (remoteObj == nullptr) {
HILOGE("get dms SA failed.");
HILOGE("get continuationMgrService SA failed.");
return nullptr;
}
return iface_cast<IDistributedAbilityManager>(remoteObj);
@ -48,70 +48,70 @@ int32_t DistributedAbilityManagerClient::Register(
const std::shared_ptr<ContinuationExtraParams>& continuationExtraParams, int32_t& token)
{
HILOGD("called.");
sptr<IDistributedAbilityManager> dmsProxy = GetDmsProxy();
if (dmsProxy == nullptr) {
HILOGE("dmsProxy is nullptr");
sptr<IDistributedAbilityManager> continuationMgrProxy = GetContinuationMgrService();
if (continuationMgrProxy == nullptr) {
HILOGE("continuationMgrProxy is nullptr");
return ERR_NULL_OBJECT;
}
return dmsProxy->Register(continuationExtraParams, token);
return continuationMgrProxy->Register(continuationExtraParams, token);
}
int32_t DistributedAbilityManagerClient::Unregister(int32_t token)
{
HILOGD("called.");
sptr<IDistributedAbilityManager> dmsProxy = GetDmsProxy();
if (dmsProxy == nullptr) {
HILOGE("dmsProxy is nullptr");
sptr<IDistributedAbilityManager> continuationMgrProxy = GetContinuationMgrService();
if (continuationMgrProxy == nullptr) {
HILOGE("continuationMgrProxy is nullptr");
return ERR_NULL_OBJECT;
}
return dmsProxy->Unregister(token);
return continuationMgrProxy->Unregister(token);
}
int32_t DistributedAbilityManagerClient::RegisterDeviceSelectionCallback(int32_t token, const std::string& cbType,
const sptr<DeviceSelectionNotifierStub>& notifier)
{
HILOGD("called.");
sptr<IDistributedAbilityManager> dmsProxy = GetDmsProxy();
if (dmsProxy == nullptr) {
HILOGE("dmsProxy is nullptr");
sptr<IDistributedAbilityManager> continuationMgrProxy = GetContinuationMgrService();
if (continuationMgrProxy == nullptr) {
HILOGE("continuationMgrProxy is nullptr");
return ERR_NULL_OBJECT;
}
return dmsProxy->RegisterDeviceSelectionCallback(token, cbType, notifier);
return continuationMgrProxy->RegisterDeviceSelectionCallback(token, cbType, notifier);
}
int32_t DistributedAbilityManagerClient::UnregisterDeviceSelectionCallback(int32_t token, const std::string& cbType)
{
HILOGD("called.");
sptr<IDistributedAbilityManager> dmsProxy = GetDmsProxy();
if (dmsProxy == nullptr) {
HILOGE("dmsProxy is nullptr");
sptr<IDistributedAbilityManager> continuationMgrProxy = GetContinuationMgrService();
if (continuationMgrProxy == nullptr) {
HILOGE("continuationMgrProxy is nullptr");
return ERR_NULL_OBJECT;
}
return dmsProxy->UnregisterDeviceSelectionCallback(token, cbType);
return continuationMgrProxy->UnregisterDeviceSelectionCallback(token, cbType);
}
int32_t DistributedAbilityManagerClient::UpdateConnectStatus(int32_t token, const std::string& deviceId,
const DeviceConnectStatus& deviceConnectStatus)
{
HILOGD("called.");
sptr<IDistributedAbilityManager> dmsProxy = GetDmsProxy();
if (dmsProxy == nullptr) {
HILOGE("dmsProxy is nullptr");
sptr<IDistributedAbilityManager> continuationMgrProxy = GetContinuationMgrService();
if (continuationMgrProxy == nullptr) {
HILOGE("continuationMgrProxy is nullptr");
return ERR_NULL_OBJECT;
}
return dmsProxy->UpdateConnectStatus(token, deviceId, deviceConnectStatus);
return continuationMgrProxy->UpdateConnectStatus(token, deviceId, deviceConnectStatus);
}
int32_t DistributedAbilityManagerClient::StartDeviceManager(
int32_t token, const std::shared_ptr<ContinuationExtraParams>& continuationExtraParams)
{
HILOGD("called.");
sptr<IDistributedAbilityManager> dmsProxy = GetDmsProxy();
if (dmsProxy == nullptr) {
HILOGE("dmsProxy is nullptr");
sptr<IDistributedAbilityManager> continuationMgrProxy = GetContinuationMgrService();
if (continuationMgrProxy == nullptr) {
HILOGE("continuationMgrProxy is nullptr");
return ERR_NULL_OBJECT;
}
return dmsProxy->StartDeviceManager(token, continuationExtraParams);
return continuationMgrProxy->StartDeviceManager(token, continuationExtraParams);
}
} // namespace DistributedSchedule
} // namespace OHOS

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Copyright (c) 2022-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
@ -16,71 +16,46 @@
#include "distributed_ability_manager_dumper.h"
#include "accesstoken_kit.h"
#include "base/continuationmgr_log.h"
#include "distributed_ability_manager_service.h"
#include "dtbschedmgr_log.h"
#include "ipc_skeleton.h"
namespace OHOS {
namespace DistributedSchedule {
namespace {
const std::string TAG = "DistributedAbilityManagerDumper";
const char* HIDUMPER_PROCESS_NAME = "hidumper_service";
constexpr size_t MIN_ARGS_SIZE = 1;
const std::string TAG = "ContinuationManagerDumper";
const std::string HIDUMPER_PROCESS_NAME = "hidumper_service";
const std::string ARGS_HELP = "-h";
const std::string ARGS_CONNECT_REMOTE_ABILITY = "-connect";
const std::string ARGS_APP_REGISTER_INFO = "-register";
constexpr size_t MIN_ARGS_SIZE = 1;
}
bool DistributedAbilityManagerDumper::Dump(const sptr<DmsDumper>& dmsDumper, const std::vector<std::string>& args,
std::string& result)
bool DistributedAbilityManagerDumper::Dump(const std::vector<std::string>& args, std::string& result)
{
result.clear();
if (!CanDump()) {
result.append("Dump failed, not allowed");
return false;
}
if (args.size() < MIN_ARGS_SIZE) {
return ProcessDistributedSchedDump(dmsDumper, args, result);
return DumpDefault(result);
}
if (args.size() == MIN_ARGS_SIZE) {
// -h
if (args[0] == ARGS_HELP) {
ShowHelp(result);
return true;
}
// -connect
if (args[0] == ARGS_CONNECT_REMOTE_ABILITY) {
return ProcessDistributedSchedDump(dmsDumper, args, result);
// -register
if (args[0] == ARGS_APP_REGISTER_INFO) {
ShowAppRegisterInfo(result);
return true;
}
}
IllegalInput(result);
return false;
}
bool DistributedAbilityManagerDumper::ProcessDistributedSchedDump(const sptr<DmsDumper>& dmsDumper,
const std::vector<std::string>& args, std::string& result)
{
if (dmsDumper == nullptr) {
HILOGE("dumper is nullptr");
return false;
}
return dmsDumper->ProcessDistributedSchedDump(args, result);
}
void DistributedAbilityManagerDumper::ShowHelp(std::string& result)
{
result.append("DistributedSched Dump options:\n")
.append(" [-h] [cmd]...\n")
.append("cmd maybe one of:\n")
.append(" -connect: show all connected remote abilities.\n");
}
void DistributedAbilityManagerDumper::IllegalInput(std::string& result)
{
result.append("The arguments are illegal and you can enter '-h' for help.\n");
}
bool DistributedAbilityManagerDumper::CanDump()
{
uint32_t accessToken = IPCSkeleton::GetCallingTokenID();
@ -91,5 +66,31 @@ bool DistributedAbilityManagerDumper::CanDump()
}
return false;
}
bool DistributedAbilityManagerDumper::DumpDefault(std::string& result)
{
result.append("ContinuationManagerService Dump\n");
result.append("\n");
ShowAppRegisterInfo(result);
return true;
}
void DistributedAbilityManagerDumper::ShowAppRegisterInfo(std::string& result)
{
DistributedAbilityManagerService::GetInstance().DumpAppRegisterInfo(result);
}
void DistributedAbilityManagerDumper::ShowHelp(std::string& result)
{
result.append("ContinuationManagerService Dump options:\n")
.append(" [-h] [cmd]...\n")
.append("cmd maybe one of:\n")
.append(" -register: show all application register infos.\n");
}
void DistributedAbilityManagerDumper::IllegalInput(std::string& result)
{
result.append("The arguments are illegal and you can enter '-h' for help.\n");
}
} // namespace DistributedSchedule
} // namespace OHOS

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Copyright (c) 2022-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
@ -15,16 +15,15 @@
#include "distributed_ability_manager_proxy.h"
#include "dtbschedmgr_log.h"
#include "base/continuationmgr_log.h"
#include "base/parcel_helper.h"
#include "ipc_types.h"
#include "parcel_helper.h"
#include "string_ex.h"
namespace OHOS {
namespace DistributedSchedule {
namespace {
const std::string TAG = "DistributedAbilityManagerProxy";
const std::u16string DMS_PROXY_INTERFACE_TOKEN = u"ohos.distributedschedule.accessToken";
const std::string TAG = "ContinuationManagerProxy";
}
int32_t DistributedAbilityManagerProxy::Register(
@ -37,7 +36,7 @@ int32_t DistributedAbilityManagerProxy::Register(
return ERR_NULL_OBJECT;
}
MessageParcel data;
if (!data.WriteInterfaceToken(DMS_PROXY_INTERFACE_TOKEN)) {
if (!data.WriteInterfaceToken(IDistributedAbilityManager::GetDescriptor())) {
return ERR_FLATTEN_OBJECT;
}
if (continuationExtraParams == nullptr) {
@ -71,7 +70,7 @@ int32_t DistributedAbilityManagerProxy::Unregister(int32_t token)
return ERR_NULL_OBJECT;
}
MessageParcel data;
if (!data.WriteInterfaceToken(DMS_PROXY_INTERFACE_TOKEN)) {
if (!data.WriteInterfaceToken(IDistributedAbilityManager::GetDescriptor())) {
return ERR_FLATTEN_OBJECT;
}
PARCEL_WRITE_HELPER(data, Int32, token);
@ -98,7 +97,7 @@ int32_t DistributedAbilityManagerProxy::RegisterDeviceSelectionCallback(
}
MessageParcel data;
if (!data.WriteInterfaceToken(DMS_PROXY_INTERFACE_TOKEN)) {
if (!data.WriteInterfaceToken(IDistributedAbilityManager::GetDescriptor())) {
return ERR_FLATTEN_OBJECT;
}
PARCEL_WRITE_HELPER(data, Int32, token);
@ -121,7 +120,7 @@ int32_t DistributedAbilityManagerProxy::UnregisterDeviceSelectionCallback(int32_
return ERR_NULL_OBJECT;
}
MessageParcel data;
if (!data.WriteInterfaceToken(DMS_PROXY_INTERFACE_TOKEN)) {
if (!data.WriteInterfaceToken(IDistributedAbilityManager::GetDescriptor())) {
return ERR_FLATTEN_OBJECT;
}
PARCEL_WRITE_HELPER(data, Int32, token);
@ -140,7 +139,7 @@ int32_t DistributedAbilityManagerProxy::UpdateConnectStatus(int32_t token, const
return ERR_NULL_OBJECT;
}
MessageParcel data;
if (!data.WriteInterfaceToken(DMS_PROXY_INTERFACE_TOKEN)) {
if (!data.WriteInterfaceToken(IDistributedAbilityManager::GetDescriptor())) {
return ERR_FLATTEN_OBJECT;
}
PARCEL_WRITE_HELPER(data, Int32, token);
@ -160,7 +159,7 @@ int32_t DistributedAbilityManagerProxy::StartDeviceManager(
return ERR_NULL_OBJECT;
}
MessageParcel data;
if (!data.WriteInterfaceToken(DMS_PROXY_INTERFACE_TOKEN)) {
if (!data.WriteInterfaceToken(IDistributedAbilityManager::GetDescriptor())) {
return ERR_FLATTEN_OBJECT;
}
PARCEL_WRITE_HELPER(data, Int32, token);

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Copyright (c) 2022-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
@ -18,48 +18,47 @@
#include <chrono>
#include <thread>
#include "adapter/dnetwork_adapter.h"
#include "ability_manager_client.h"
#include "base/continuationmgr_log.h"
#include "base/parcel_helper.h"
#include "bundlemgr/bundle_mgr_interface.h"
#include "bundlemgr/bundle_mgr_proxy.h"
#include "continuation_manager/app_connection_stub.h"
#include "continuation_manager/app_device_callback_stub.h"
#include "continuation_manager/device_selection_notifier_proxy.h"
#include "continuation_manager/notifier_death_recipient.h"
#include "dlfcn.h"
#include "distributed_ability_manager_dumper.h"
#include "dtbschedmgr_device_info_storage.h"
#include "dtbschedmgr_log.h"
#include "file_ex.h"
#include "ipc_skeleton.h"
#include "iservice_registry.h"
#include "os_account_manager.h"
#include "parameters.h"
#include "parcel_helper.h"
#include "system_ability_definition.h"
namespace OHOS {
namespace DistributedSchedule {
namespace {
const std::string TAG = "DistributedAbilityManagerService";
const std::string TAG = "ContinuationManagerService";
const std::u16string HIPLAY_PANEL_INTERFACE_TOKEN = u"ohos.hiplay.panel";
const std::string TOKEN_KEY = "distributedsched.continuationmanager.token";
const std::string DEFAULT_TOKEN_VALUE = "0";
const std::string DMS_HIPLAY_ACTION = "ohos.ability.action.deviceSelect";
constexpr int32_t MAX_TOKEN_NUM = 100000000;
constexpr int32_t MAX_REGISTER_NUM = 600;
constexpr int32_t START_DEVICE_MANAGER_CODE = 1;
constexpr int32_t UPDATE_CONNECT_STATUS_CODE = 2;
}
REGISTER_SYSTEM_ABILITY_BY_ID(DistributedAbilityManagerService, DISTRIBUTED_SCHED_SA_ID, true);
IMPLEMENT_SINGLE_INSTANCE(DistributedAbilityManagerService);
const bool REGISTER_RESULT = SystemAbility::MakeAndRegisterAbility(&DistributedAbilityManagerService::GetInstance());
DistributedAbilityManagerService::DistributedAbilityManagerService(
int32_t systemAbilityId, bool runOnCreate) : SystemAbility(systemAbilityId, runOnCreate)
DistributedAbilityManagerService::DistributedAbilityManagerService() : SystemAbility(CONTINUATION_MANAGER_SA_ID, true)
{
}
void DistributedAbilityManagerService::OnStart()
{
HILOGI("begin");
DnetworkAdapter::GetInstance()->Init();
if (!DtbschedmgrDeviceInfoStorage::GetInstance().Init(this)) {
HILOGW("Init DtbschedmgrDeviceInfoStorage init failed.");
}
{
std::lock_guard<std::mutex> tokenLock(tokenMutex_);
std::string tokenStr = system::GetParameter(TOKEN_KEY, DEFAULT_TOKEN_VALUE);
@ -67,7 +66,7 @@ void DistributedAbilityManagerService::OnStart()
token_.store(std::stoi(tokenStr));
}
}
notifierDeathRecipient_ = sptr<IRemoteObject::DeathRecipient>(new NotifierDeathRecipient(this));
notifierDeathRecipient_ = sptr<IRemoteObject::DeathRecipient>(new NotifierDeathRecipient());
if (continuationHandler_ == nullptr) {
auto runner = AppExecFwk::EventRunner::Create("continuation_manager");
continuationHandler_ = std::make_shared<AppExecFwk::EventHandler>(runner);
@ -80,110 +79,64 @@ void DistributedAbilityManagerService::OnStop()
HILOGI("begin");
}
bool DistributedAbilityManagerService::InitDmsImplFunc()
int32_t DistributedAbilityManagerService::Dump(int32_t fd, const std::vector<std::u16string>& args)
{
std::lock_guard<std::mutex> lock(libLoadLock_);
if (isLoaded_) {
return true;
std::vector<std::string> argsInStr8;
for (const auto& arg : args) {
argsInStr8.emplace_back(Str16ToStr8(arg));
}
HILOGI("begin");
dmsImplHandle_ = dlopen("libdistributedschedsvr.z.so", RTLD_NOW);
if (dmsImplHandle_ == nullptr) {
HILOGE("dlopen libdistributedschedsvr failed with errno:%s!", dlerror());
return false;
std::string result;
DistributedAbilityManagerDumper::Dump(argsInStr8, result);
if (!SaveStringToFd(fd, result)) {
HILOGE("save to fd failed");
return DMS_WRITE_FILE_FAILED_ERR;
}
if (!InitFunc()) {
dlclose(dmsImplHandle_);
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;
return ERR_OK;
}
bool DistributedAbilityManagerService::InitFunc()
void DistributedAbilityManagerService::DumpAppRegisterInfo(std::string& info)
{
onRemoteRequestFunc_ = reinterpret_cast<OnRemoteRequestFunc>(dlsym(dmsImplHandle_, "OnRemoteRequest"));
if (onRemoteRequestFunc_ == nullptr) {
HILOGE("get OnRemoteRequest function error");
return false;
}
deviceOnlineNotifyFunc_ = reinterpret_cast<DeviceOnlineNotifyFunc>(dlsym(dmsImplHandle_, "DeviceOnlineNotify"));
if (deviceOnlineNotifyFunc_ == nullptr) {
HILOGE("get DeviceOnlineNotify function error");
return false;
}
deviceOfflineNotifyFunc_ = reinterpret_cast<DeviceOfflineNotifyFunc>(dlsym(dmsImplHandle_, "DeviceOfflineNotify"));
if (deviceOfflineNotifyFunc_ == nullptr) {
HILOGE("get DeviceOfflineNotify function error");
return false;
}
connectAbilityFunc_ = reinterpret_cast<ConnectAbilityFunc>(dlsym(dmsImplHandle_, "ConnectAbility"));
if (connectAbilityFunc_ == nullptr) {
HILOGE("get ConnectAbility function error");
return false;
}
disconnectAbilityFunc_ = reinterpret_cast<DisconnectAbilityFunc>(dlsym(dmsImplHandle_, "DisconnectAbility"));
if (disconnectAbilityFunc_ == nullptr) {
HILOGE("get DisconnectAbility function error");
return false;
}
distributedSchedDumpFunc_ = reinterpret_cast<DistributedSchedDumpFunc>(dlsym(dmsImplHandle_,
"DistributedSchedDump"));
if (distributedSchedDumpFunc_ == nullptr) {
HILOGE("get Dump function error");
return false;
}
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);
std::lock_guard<std::mutex> autoLock(tokenMapMutex_);
info += "application register infos:\n";
info += " ";
if (!tokenMap_.empty()) {
for (const auto& tokenMap : tokenMap_) {
info += "accessToken: ";
info += std::to_string(tokenMap.first);
std::vector<int32_t> tokenVec = tokenMap.second;
DumpNotifierLocked(tokenVec, info);
info += "\n";
info += " ";
}
} else {
info += " <none info>\n";
}
}
void DistributedAbilityManagerService::DeviceOfflineNotify(const std::string& deviceId)
void DistributedAbilityManagerService::DumpNotifierLocked(const std::vector<int32_t>& tokenVec, std::string& info)
{
if (InitDmsImplFunc()) {
deviceOfflineNotifyFunc_(deviceId);
for (const auto& token : tokenVec) {
info += ", ";
info += "token: ";
info += std::to_string(token);
if (callbackMap_.find(token) == callbackMap_.end()) {
continue;
}
if (!callbackMap_[token]->IsNotifierMapEmpty()) {
info += ", ";
info += "cbType: ";
if (callbackMap_[token]->GetNotifier(EVENT_CONNECT) != nullptr) {
info += " ";
info += EVENT_CONNECT;
}
if (callbackMap_[token]->GetNotifier(EVENT_DISCONNECT) != nullptr) {
info += " ";
info += EVENT_DISCONNECT;
}
}
}
}
int32_t DistributedAbilityManagerService::ConnectAbility(const sptr<DmsNotifier>& dmsNotifier, int32_t token,
const std::shared_ptr<ContinuationExtraParams>& continuationExtraParams)
{
if (InitDmsImplFunc()) {
return connectAbilityFunc_(dmsNotifier, token, continuationExtraParams);
}
return INVALID_PARAMETERS_ERR;
}
int32_t DistributedAbilityManagerService::DisconnectAbility()
{
if (InitDmsImplFunc()) {
return disconnectAbilityFunc_();
}
return INVALID_PARAMETERS_ERR;
}
int32_t DistributedAbilityManagerService::Register(
const std::shared_ptr<ContinuationExtraParams>& continuationExtraParams, int32_t& token)
{
@ -374,7 +327,7 @@ int32_t DistributedAbilityManagerService::StartDeviceManager(
return ERR_OK;
}
}
int32_t errCode = ConnectAbility(this, token, continuationExtraParams);
int32_t errCode = ConnectAbility(token, continuationExtraParams);
if (errCode != ERR_OK) {
HILOGE("token %{public}d connect to app failed", token);
return CONNECT_ABILITY_FAILED;
@ -383,6 +336,95 @@ int32_t DistributedAbilityManagerService::StartDeviceManager(
return ERR_OK;
}
int32_t DistributedAbilityManagerService::ConnectAbility(int32_t token,
const std::shared_ptr<ContinuationExtraParams>& continuationExtraParams)
{
AAFwk::Want want;
want.SetAction(DMS_HIPLAY_ACTION);
std::vector<int32_t> ids;
int32_t errCode = AccountSA::OsAccountManager::QueryActiveOsAccountIds(ids);
if (errCode != ERR_OK || ids.empty()) {
return INVALID_PARAMETERS_ERR;
}
AppExecFwk::ExtensionAbilityInfo extensionInfo;
if (!QueryExtensionAbilityInfo(ids, want, extensionInfo)) {
HILOGE("QueryExtensionAbilityInfo failed");
return CONNECT_ABILITY_FAILED;
}
if (connect_ == nullptr) {
connect_ = new AppConnectionStub(token, continuationExtraParams);
}
errCode = AAFwk::AbilityManagerClient::GetInstance()->Connect();
if (errCode != ERR_OK) {
HILOGE("connect ability manager server failed, errCode=%{public}d", errCode);
return errCode;
}
errCode = AAFwk::AbilityManagerClient::GetInstance()->ConnectAbility(want,
iface_cast<AAFwk::IAbilityConnection>(connect_), this, ids[0]);
if (errCode != ERR_OK) {
HILOGE("ConnectAbility failed");
connect_ = nullptr;
return CONNECT_ABILITY_FAILED;
}
return ERR_OK;
}
bool DistributedAbilityManagerService::QueryExtensionAbilityInfo(const std::vector<int32_t>& ids,
const AAFwk::Want& want, AppExecFwk::ExtensionAbilityInfo& extensionInfo)
{
auto samgrProxy = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
if (samgrProxy == nullptr) {
HILOGE("get samgr failed");
return false;
}
sptr<IRemoteObject> bmsProxy = samgrProxy->GetSystemAbility(BUNDLE_MGR_SERVICE_SYS_ABILITY_ID);
if (bmsProxy == nullptr) {
HILOGE("get bms from samgr failed");
return false;
}
auto bundleMgr = iface_cast<AppExecFwk::IBundleMgr>(bmsProxy);
if (bundleMgr == nullptr) {
HILOGE("bms iface_cast failed");
return false;
}
std::vector<AppExecFwk::ExtensionAbilityInfo> extensionInfos;
std::string identity = IPCSkeleton::ResetCallingIdentity();
bundleMgr->QueryExtensionAbilityInfos(want, AppExecFwk::AbilityInfoFlag::GET_ABILITY_INFO_DEFAULT
| AppExecFwk::AbilityInfoFlag::GET_ABILITY_INFO_WITH_PERMISSION, ids[0], extensionInfos);
IPCSkeleton::SetCallingIdentity(identity);
if (extensionInfos.empty()) {
HILOGE("QueryExtensionAbilityInfo failed");
return false;
}
extensionInfo = extensionInfos.front();
if (extensionInfo.bundleName.empty() || extensionInfo.name.empty()) {
HILOGE("ExtensionAbilityInfo is empty.");
return false;
}
HILOGD("ExtensionAbilityInfo found, name=%{public}s.", extensionInfo.name.c_str());
return true;
}
int32_t DistributedAbilityManagerService::DisconnectAbility()
{
if (connect_ == nullptr) {
return ERR_NULL_OBJECT;
}
int32_t errCode = AAFwk::AbilityManagerClient::GetInstance()->Connect();
if (errCode != ERR_OK) {
HILOGE("connect ability manager server failed, errCode=%{public}d", errCode);
return errCode;
}
errCode = AAFwk::AbilityManagerClient::GetInstance()->DisconnectAbility(
iface_cast<AAFwk::IAbilityConnection>(connect_));
connect_ = nullptr;
if (errCode != ERR_OK) {
HILOGE("DisconnectAbility failed");
return DISCONNECT_ABILITY_FAILED;
}
return ERR_OK;
}
int32_t DistributedAbilityManagerService::OnDeviceConnect(int32_t token,
const std::vector<ContinuationResult>& continuationResults)
{
@ -591,7 +633,7 @@ void DistributedAbilityManagerService::HandleStartDeviceManager(int32_t token,
PARCEL_WRITE_HELPER_NORET(data, Int32, VALUE_OBJECT);
PARCEL_WRITE_HELPER_NORET(data, Parcelable, continuationExtraParams.get());
}
sptr<AppDeviceCallbackStub> callback = new AppDeviceCallbackStub(this);
sptr<AppDeviceCallbackStub> callback = new AppDeviceCallbackStub();
PARCEL_WRITE_HELPER_NORET(data, RemoteObject, callback);
// query whether the connect status needs to be send
{
@ -710,42 +752,5 @@ void DistributedAbilityManagerService::HandleNotifierDied(const sptr<IRemoteObje
};
continuationHandler_->PostTask(func);
}
bool DistributedAbilityManagerService::IsDistributedSchedLoaded()
{
return isLoaded_;
}
int32_t DistributedAbilityManagerService::Dump(int32_t fd, const std::vector<std::u16string>& args)
{
std::vector<std::string> argsInStr8;
for (const auto& arg : args) {
argsInStr8.emplace_back(Str16ToStr8(arg));
}
std::string result;
DistributedAbilityManagerDumper::Dump(this, argsInStr8, result);
if (!SaveStringToFd(fd, result)) {
HILOGE("save to fd failed");
return DMS_WRITE_FILE_FAILED_ERR;
}
return ERR_OK;
}
bool DistributedAbilityManagerService::ProcessDistributedSchedDump(const std::vector<std::string>& args,
std::string& result)
{
std::lock_guard<std::mutex> lock(libLoadLock_);
if (!IsDistributedSchedLoaded() || distributedSchedDumpFunc_ == nullptr) {
result.append("<none info>\n");
return false;
}
if (!distributedSchedDumpFunc_(args, result)) {
HILOGE("distributedSched dump failed");
return false;
}
return true;
}
} // namespace DistributedSchedule
} // namespace OHOS

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Copyright (c) 2022-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
@ -21,21 +21,19 @@
#include <utility>
#include "accesstoken_kit.h"
#include "base/continuationmgr_log.h"
#include "base/parcel_helper.h"
#include "continuation_extra_params.h"
#include "device_connect_status.h"
#include "dtbschedmgr_log.h"
#include "iremote_object.h"
#include "parcel_helper.h"
#include "ipc_skeleton.h"
namespace OHOS {
namespace DistributedSchedule {
using namespace OHOS::Security;
namespace {
const std::string TAG = "DistributedAbilityManagerStub";
const std::string TAG = "ContinuationManagerStub";
const std::string PERMISSION_DISTRIBUTED_DATASYNC = "ohos.permission.DISTRIBUTED_DATASYNC";
const std::u16string DMS_STUB_INTERFACE_TOKEN = u"ohos.distributedschedule.accessToken";
constexpr int32_t GET_DISTRIBUTED_COMPONENT_LIST_REQUEST_CODE = 161;
}
DistributedAbilityManagerStub::DistributedAbilityManagerStub()
@ -48,15 +46,11 @@ DistributedAbilityManagerStub::DistributedAbilityManagerStub()
&DistributedAbilityManagerStub::UnregisterDeviceSelectionCallbackInner;
funcsMap_[UPDATE_CONNECT_STATUS] = &DistributedAbilityManagerStub::UpdateConnectStatusInner;
funcsMap_[START_DEVICE_MANAGER] = &DistributedAbilityManagerStub::StartDeviceManagerInner;
distributedFuncMap_[GET_DISTRIBUTED_COMPONENT_LIST_REQUEST_CODE] =
&DistributedAbilityManagerStub::GetDistributedComponentListInner;
}
DistributedAbilityManagerStub::~DistributedAbilityManagerStub()
{
funcsMap_.clear();
distributedFuncMap_.clear();
}
int32_t DistributedAbilityManagerStub::OnRemoteRequest(uint32_t code, MessageParcel& data,
@ -82,23 +76,13 @@ int32_t DistributedAbilityManagerStub::OnRemoteRequest(uint32_t code, MessagePar
return ERR_NULL_OBJECT;
}
}
auto distributedFuncIter = distributedFuncMap_.find(code);
if (distributedFuncIter != distributedFuncMap_.end()) {
auto func = distributedFuncIter->second;
if (func != nullptr) {
return (this->*func)(data, reply, option);
} else {
HILOGE("func is nullptr");
return ERR_NULL_OBJECT;
}
}
return SendRequestToImpl(code, data, reply, option);
return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
}
bool DistributedAbilityManagerStub::EnforceInterfaceToken(MessageParcel& data)
{
std::u16string interfaceToken = data.ReadInterfaceToken();
return interfaceToken == DMS_STUB_INTERFACE_TOKEN;
return interfaceToken == IDistributedAbilityManager::GetDescriptor();
}
int32_t DistributedAbilityManagerStub::RegisterInner(MessageParcel& data, MessageParcel& reply)
@ -204,23 +188,6 @@ int32_t DistributedAbilityManagerStub::StartDeviceManagerInner(MessageParcel& da
return ERR_NONE;
}
int32_t DistributedAbilityManagerStub::GetDistributedComponentListInner(MessageParcel& data,
MessageParcel& reply, MessageOption& option)
{
if (IsDistributedSchedLoaded()) {
return SendRequestToImpl(GET_DISTRIBUTED_COMPONENT_LIST_REQUEST_CODE, data, reply, option);
}
if (!EnforceInterfaceToken(data)) {
HILOGE("interface token check failed!");
return DMS_PERMISSION_DENIED;
}
HILOGI("DistributedSched is not loaded, return empty");
PARCEL_WRITE_HELPER(reply, Int32, ERR_NONE);
std::vector<std::string> distributedComponents;
PARCEL_WRITE_HELPER(reply, StringVector, distributedComponents);
return ERR_NONE;
}
bool DistributedAbilityManagerStub::VerifyPermission(uint32_t accessToken, const std::string& permissionName) const
{
int32_t result = AccessToken::AccessTokenKit::VerifyAccessToken(accessToken, permissionName);

View File

@ -1,4 +1,4 @@
# Copyright (c) 2022 Huawei Device Co., Ltd.
# Copyright (c) 2022-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
@ -39,20 +39,24 @@ dtbabilitymgr_external_deps = [
"access_token:libaccesstoken_sdk",
"access_token:libnativetoken",
"access_token:libtoken_setproc",
"bundle_framework:appexecfwk_base",
"bundle_framework:appexecfwk_core",
"c_utils:utils",
"device_auth:deviceauth_sdk",
"device_manager:devicemanagersdk",
"dmsfwk:common_sdk",
"dmsfwk:continuation_manager",
"eventhandler:libeventhandler",
"hiviewdfx_hilog_native:libhilog",
"init:libbegetutil",
"ipc:ipc_core",
"kv_store:distributeddata_inner",
"os_account:os_account_innerkits",
"safwk:system_ability_fwk",
"samgr:samgr_proxy",
]
dtbabilitymgr_public_deps = [
"//foundation/ability/dmsfwk/services/base:dmsbaseinner",
"//foundation/ability/dmsfwk/services/dtbschedmgr:distributedschedsvr",
"//third_party/googletest:gmock_main",
"//third_party/googletest:gtest_main",
@ -60,6 +64,8 @@ dtbabilitymgr_public_deps = [
]
dtbabilitymgr_sources = [
"${distributed_service}/dtbabilitymgr/src/continuation_manager/app_connection_stub.cpp",
"${distributed_service}/dtbabilitymgr/src/continuation_manager/app_device_callback_stub.cpp",
"${distributed_service}/dtbabilitymgr/src/continuation_manager/connect_status_info.cpp",
"${distributed_service}/dtbabilitymgr/src/continuation_manager/continuation_extra_params.cpp",
"${distributed_service}/dtbabilitymgr/src/continuation_manager/continuation_result.cpp",
@ -68,6 +74,7 @@ dtbabilitymgr_sources = [
"${distributed_service}/dtbabilitymgr/src/continuation_manager/notifier_death_recipient.cpp",
"${distributed_service}/dtbabilitymgr/src/continuation_manager/notifier_info.cpp",
"${distributed_service}/dtbabilitymgr/src/distributed_ability_manager_client.cpp",
"${distributed_service}/dtbabilitymgr/src/distributed_ability_manager_dumper.cpp",
"${distributed_service}/dtbabilitymgr/src/distributed_ability_manager_proxy.cpp",
"${distributed_service}/dtbabilitymgr/src/distributed_ability_manager_service.cpp",
"${distributed_service}/dtbabilitymgr/src/distributed_ability_manager_stub.cpp",
@ -77,8 +84,8 @@ ohos_unittest("continuationmanagertest") {
module_out_path = module_output_path
sources = [
"${distributed_service}/dtbschedmgr/test/unittest/distributed_sched_util.cpp",
"unittest/continuation_manager/app_connection_stub_test.cpp",
"unittest/continuation_manager/continuation_manager_test.cpp",
"unittest/distributed_ability_manager_dumper_test.cpp",
]
sources += dtbabilitymgr_sources
configs = [
@ -98,20 +105,12 @@ ohos_unittest("continuationmanagertest") {
ohos_unittest("distributedabilitymanagerservicetest") {
module_out_path = module_output_path
sources = [
"${distributed_service}/dtbabilitymgr/src/continuation_manager/app_device_callback_stub.cpp",
"${distributed_service}/dtbabilitymgr/src/continuation_manager/connect_status_info.cpp",
"${distributed_service}/dtbabilitymgr/src/continuation_manager/continuation_extra_params.cpp",
"${distributed_service}/dtbabilitymgr/src/continuation_manager/continuation_result.cpp",
"${distributed_service}/dtbabilitymgr/src/continuation_manager/device_selection_notifier_proxy.cpp",
"${distributed_service}/dtbabilitymgr/src/continuation_manager/notifier_death_recipient.cpp",
"${distributed_service}/dtbabilitymgr/src/continuation_manager/notifier_info.cpp",
"${distributed_service}/dtbabilitymgr/src/distributed_ability_manager_dumper.cpp",
"${distributed_service}/dtbabilitymgr/src/distributed_ability_manager_service.cpp",
"${distributed_service}/dtbabilitymgr/src/distributed_ability_manager_stub.cpp",
"${distributed_service}/dtbschedmgr/test/unittest/distributed_sched_util.cpp",
"unittest/distributed_ability_manager_dumper_test.cpp",
"unittest/distributed_ability_manager_service_test.cpp",
"unittest/distributed_ability_manager_stub_test.cpp",
]
sources += dtbabilitymgr_sources
configs = [
":test_config",
"${distributed_service}/dtbschedmgr/test/resource:coverage_flags",

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Copyright (c) 2022-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
@ -26,53 +26,6 @@ namespace {
const std::u16string MOCK_INVALID_DESCRIPTOR = u"invalid descriptor";
}
class MockDmsNotifier : public DmsNotifier {
public:
MockDmsNotifier() = default;
~MockDmsNotifier() = default;
void DeviceOnlineNotify(const std::string& deviceId) override;
void DeviceOfflineNotify(const std::string& deviceId) override;
void ProcessNotifierDied(const sptr<IRemoteObject>& notifier) override;
void ScheduleStartDeviceManager(const sptr<IRemoteObject>& appProxy, int32_t token,
const std::shared_ptr<ContinuationExtraParams>& continuationExtraParams = nullptr) override;
int32_t OnDeviceConnect(int32_t token, const std::vector<ContinuationResult>& continuationResults) override;
int32_t OnDeviceDisconnect(int32_t token, const std::vector<ContinuationResult>& continuationResults) override;
int32_t OnDeviceCancel() override;
};
void MockDmsNotifier::DeviceOnlineNotify(const std::string& deviceId)
{
}
void MockDmsNotifier::DeviceOfflineNotify(const std::string& deviceId)
{
}
void MockDmsNotifier::ProcessNotifierDied(const sptr<IRemoteObject>& notifier)
{
}
void MockDmsNotifier::ScheduleStartDeviceManager(const sptr<IRemoteObject>& appProxy, int32_t token,
const std::shared_ptr<ContinuationExtraParams>& continuationExtraParams)
{
}
int32_t MockDmsNotifier::OnDeviceConnect(int32_t token, const std::vector<ContinuationResult>& continuationResults)
{
return 0;
}
int32_t MockDmsNotifier::OnDeviceDisconnect(int32_t token, const std::vector<ContinuationResult>& continuationResults)
{
return 0;
}
int32_t MockDmsNotifier::OnDeviceCancel()
{
return 0;
}
void AppConnectionStubTest::SetUpTestCase()
{
DTEST_LOG << "AppConnectionStubTest::SetUpTestCase" << std::endl;
@ -90,10 +43,9 @@ void AppConnectionStubTest::TearDown()
void AppConnectionStubTest::SetUp()
{
sptr<DmsNotifier> dmsNotifier(new MockDmsNotifier());
int32_t token = 0;
std::shared_ptr<ContinuationExtraParams> continuationExtraParams = std::make_shared<ContinuationExtraParams>();
appConnectionStub_ = new AppConnectionStub(dmsNotifier, token, continuationExtraParams);
appConnectionStub_ = new AppConnectionStub(token, continuationExtraParams);
DTEST_LOG << "AppConnectionStubTest::SetUp" << std::endl;
}
@ -242,7 +194,6 @@ HWTEST_F(AppConnectionStubTest, AppConnectionStubTest_007, TestSize.Level3)
data.WriteParcelable(&element);
data.WriteRemoteObject((new MockRemoteStub())->AsObject());
code = AppConnectionStub::ON_ABILITY_CONNECT_DONE;
appConnectionStub_->dmsNotifier_ = nullptr;
int32_t result = appConnectionStub_->OnRemoteRequest(code, data, reply, option);
EXPECT_EQ(result, ERR_NONE);
DTEST_LOG << "AppConnectionStubTest AppConnectionStubTest_007 end" << std::endl;
@ -265,7 +216,6 @@ HWTEST_F(AppConnectionStubTest, AppConnectionStubTest_008, TestSize.Level3)
AppExecFwk::ElementName element;
data.WriteParcelable(&element);
code = AppConnectionStub::ON_ABILITY_DISCONNECT_DONE;
appConnectionStub_->dmsNotifier_ = nullptr;
int32_t result = appConnectionStub_->OnRemoteRequest(code, data, reply, option);
EXPECT_EQ(result, ERR_NONE);
DTEST_LOG << "AppConnectionStubTest AppConnectionStubTest_008 end" << std::endl;

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Copyright (c) 2022-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
@ -19,7 +19,7 @@
#include "gtest/gtest.h"
#define private public
#include "app_connection_stub.h"
#include "continuation_manager/app_connection_stub.h"
#undef private
namespace OHOS {

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Copyright (c) 2022-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
@ -27,7 +27,6 @@ using namespace std;
using namespace testing;
using namespace testing::ext;
namespace {
constexpr int32_t DISTRIBUTED_SCHED_SA_ID = 1401;
constexpr int32_t INVALID_LEN = -1;
constexpr int32_t UNREGISTER_TOKEN = 10000;
constexpr int32_t TEST_TOKEN = 1000;
@ -90,38 +89,6 @@ void DeviceSelectionNotifierTest::OnDeviceDisconnect(const std::vector<Continuat
}
}
void MockDmsNotifier::DeviceOnlineNotify(const std::string& deviceId)
{
}
void MockDmsNotifier::DeviceOfflineNotify(const std::string& deviceId)
{
}
void MockDmsNotifier::ProcessNotifierDied(const sptr<IRemoteObject>& notifier)
{
}
void MockDmsNotifier::ScheduleStartDeviceManager(const sptr<IRemoteObject>& appProxy, int32_t token,
const std::shared_ptr<ContinuationExtraParams>& continuationExtraParams)
{
}
int32_t MockDmsNotifier::OnDeviceConnect(int32_t token, const std::vector<ContinuationResult>& continuationResults)
{
return 0;
}
int32_t MockDmsNotifier::OnDeviceDisconnect(int32_t token, const std::vector<ContinuationResult>& continuationResults)
{
return 0;
}
int32_t MockDmsNotifier::OnDeviceCancel()
{
return 0;
}
void ContinuationManagerTest::SetUpTestCase()
{
DTEST_LOG << "ContinuationManagerTest::SetUpTestCase" << std::endl;
@ -134,7 +101,7 @@ void ContinuationManagerTest::TearDownTestCase()
void ContinuationManagerTest::SetUp()
{
dtbabilitymgrService_ = new DistributedAbilityManagerService(DISTRIBUTED_SCHED_SA_ID, true);
dtbabilitymgrService_ = new DistributedAbilityManagerService();
DTEST_LOG << "ContinuationManagerTest::SetUp" << std::endl;
}
@ -1744,9 +1711,7 @@ HWTEST_F(ContinuationManagerTest, OnRemoteRequest_004, TestSize.Level3)
/**
* @tc.steps: step2. test OnRemoteDied when dmsNotifier_ == nullptr.
*/
sptr<DmsNotifier> dmsNotifier = new MockDmsNotifier();
NotifierDeathRecipient notifierDeathRecipient(dmsNotifier);
notifierDeathRecipient.dmsNotifier_ = nullptr;
NotifierDeathRecipient notifierDeathRecipient;
wptr<IRemoteObject> remote = nullptr;
notifierDeathRecipient.OnRemoteDied(remote);
}
@ -1836,8 +1801,7 @@ HWTEST_F(ContinuationManagerTest, OnRemoteRequest_007, TestSize.Level3)
*/
HWTEST_F(ContinuationManagerTest, OnRemoteRequest_008, TestSize.Level3)
{
sptr<DmsNotifier> dmsNotifier = new MockDmsNotifier();
AppDeviceCallbackStub appDeviceCallbackStub(dmsNotifier);
AppDeviceCallbackStub appDeviceCallbackStub;
MessageParcel data;
MessageParcel reply;
MessageOption option;
@ -1887,8 +1851,7 @@ HWTEST_F(ContinuationManagerTest, OnRemoteRequest_008, TestSize.Level3)
*/
HWTEST_F(ContinuationManagerTest, OnRemoteRequest_009, TestSize.Level3)
{
sptr<DmsNotifier> dmsNotifier = new MockDmsNotifier();
AppDeviceCallbackStub appDeviceCallbackStub(dmsNotifier);
AppDeviceCallbackStub appDeviceCallbackStub;
MessageParcel data;
MessageParcel reply;
MessageOption option;
@ -1896,7 +1859,7 @@ HWTEST_F(ContinuationManagerTest, OnRemoteRequest_009, TestSize.Level3)
data.WriteInt32(TEST_TOKEN);
int32_t ret = appDeviceCallbackStub.OnRemoteRequest(
AppDeviceCallbackInterface::EVENT_DEVICE_CONNECT, data, reply, option);
EXPECT_EQ(ERR_NONE, ret);
EXPECT_EQ(DISCONNECT_ABILITY_FAILED, ret);
}
/**
@ -1907,8 +1870,7 @@ HWTEST_F(ContinuationManagerTest, OnRemoteRequest_009, TestSize.Level3)
*/
HWTEST_F(ContinuationManagerTest, OnRemoteRequest_010, TestSize.Level3)
{
sptr<DmsNotifier> dmsNotifier = new MockDmsNotifier();
AppDeviceCallbackStub appDeviceCallbackStub(dmsNotifier);
AppDeviceCallbackStub appDeviceCallbackStub;
MessageParcel data;
MessageParcel reply;
MessageOption option;
@ -1929,8 +1891,7 @@ HWTEST_F(ContinuationManagerTest, OnRemoteRequest_010, TestSize.Level3)
*/
HWTEST_F(ContinuationManagerTest, OnRemoteRequest_011, TestSize.Level3)
{
sptr<DmsNotifier> dmsNotifier = new MockDmsNotifier();
AppDeviceCallbackStub appDeviceCallbackStub(dmsNotifier);
AppDeviceCallbackStub appDeviceCallbackStub;
MessageParcel data;
MessageParcel reply;
MessageOption option;
@ -1938,7 +1899,7 @@ HWTEST_F(ContinuationManagerTest, OnRemoteRequest_011, TestSize.Level3)
data.WriteInt32(TEST_TOKEN);
int32_t ret = appDeviceCallbackStub.OnRemoteRequest(
AppDeviceCallbackInterface::EVENT_DEVICE_DISCONNECT, data, reply, option);
EXPECT_EQ(ERR_NONE, ret);
EXPECT_EQ(DISCONNECT_ABILITY_FAILED, ret);
}
/**
@ -1949,8 +1910,7 @@ HWTEST_F(ContinuationManagerTest, OnRemoteRequest_011, TestSize.Level3)
*/
HWTEST_F(ContinuationManagerTest, OnRemoteRequest_012, TestSize.Level3)
{
sptr<DmsNotifier> dmsNotifier = new MockDmsNotifier();
AppDeviceCallbackStub appDeviceCallbackStub(dmsNotifier);
AppDeviceCallbackStub appDeviceCallbackStub;
MessageParcel data;
MessageParcel reply;
MessageOption option;
@ -1971,15 +1931,14 @@ HWTEST_F(ContinuationManagerTest, OnRemoteRequest_012, TestSize.Level3)
*/
HWTEST_F(ContinuationManagerTest, OnRemoteRequest_013, TestSize.Level3)
{
sptr<DmsNotifier> dmsNotifier = new MockDmsNotifier();
AppDeviceCallbackStub appDeviceCallbackStub(dmsNotifier);
AppDeviceCallbackStub appDeviceCallbackStub;
MessageParcel data;
MessageParcel reply;
MessageOption option;
data.WriteInterfaceToken(AppDeviceCallbackInterface::GetDescriptor());
int32_t ret = appDeviceCallbackStub.OnRemoteRequest(
AppDeviceCallbackInterface::EVENT_DEVICE_CANCEL, data, reply, option);
EXPECT_EQ(ERR_NONE, ret);
EXPECT_EQ(DISCONNECT_ABILITY_FAILED, ret);
}
/**
@ -1990,8 +1949,7 @@ HWTEST_F(ContinuationManagerTest, OnRemoteRequest_013, TestSize.Level3)
*/
HWTEST_F(ContinuationManagerTest, OnRemoteRequest_014, TestSize.Level3)
{
sptr<DmsNotifier> dmsNotifier = new MockDmsNotifier();
AppDeviceCallbackStub appDeviceCallbackStub(dmsNotifier);
AppDeviceCallbackStub appDeviceCallbackStub;
MessageParcel data;
MessageParcel reply;
MessageOption option;
@ -2008,40 +1966,23 @@ HWTEST_F(ContinuationManagerTest, OnRemoteRequest_014, TestSize.Level3)
*/
HWTEST_F(ContinuationManagerTest, OnDeviceEvent_001, TestSize.Level3)
{
sptr<DmsNotifier> dmsNotifier = new MockDmsNotifier();
AppDeviceCallbackStub appDeviceCallbackStub(dmsNotifier);
AppDeviceCallbackStub appDeviceCallbackStub;
std::vector<ContinuationResult> continuationResults;
/**
* @tc.steps: step1. test OnDeviceConnect
*/
int32_t ret = appDeviceCallbackStub.OnDeviceConnect(TEST_TOKEN, continuationResults);
EXPECT_EQ(ERR_NONE, ret);
EXPECT_EQ(DISCONNECT_ABILITY_FAILED, ret);
/**
* @tc.steps: step2. test OnDeviceDisconnect
*/
ret = appDeviceCallbackStub.OnDeviceDisconnect(TEST_TOKEN, continuationResults);
EXPECT_EQ(ERR_NONE, ret);
EXPECT_EQ(DISCONNECT_ABILITY_FAILED, ret);
/**
* @tc.steps: step3. test OnDeviceCancel
*/
ret = appDeviceCallbackStub.OnDeviceCancel();
EXPECT_EQ(ERR_NONE, ret);
appDeviceCallbackStub.dmsNotifier_ = nullptr;
/**
* @tc.steps: step4. test OnDeviceConnect when dmsNotifier_ == nullptr
*/
ret = appDeviceCallbackStub.OnDeviceConnect(TEST_TOKEN, continuationResults);
EXPECT_EQ(ERR_NULL_OBJECT, ret);
/**
* @tc.steps: step5. test OnDeviceDisconnect when dmsNotifier_ == nullptr
*/
ret = appDeviceCallbackStub.OnDeviceDisconnect(TEST_TOKEN, continuationResults);
EXPECT_EQ(ERR_NULL_OBJECT, ret);
/**
* @tc.steps: step6. test OnDeviceCancel when dmsNotifier_ == nullptr
*/
ret = appDeviceCallbackStub.OnDeviceCancel();
EXPECT_EQ(ERR_NULL_OBJECT, ret);
EXPECT_EQ(DISCONNECT_ABILITY_FAILED, ret);
}
/**

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Copyright (c) 2022-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
@ -47,22 +47,6 @@ public:
void OnDeviceConnect(const std::vector<ContinuationResult>& continuationResults) override;
void OnDeviceDisconnect(const std::vector<ContinuationResult>& continuationResults) override;
};
class MockDmsNotifier : public DmsNotifier {
public:
MockDmsNotifier() = default;
~MockDmsNotifier() = default;
void DeviceOnlineNotify(const std::string& deviceId) override;
void DeviceOfflineNotify(const std::string& deviceId) override;
void ProcessNotifierDied(const sptr<IRemoteObject>& notifier) override;
void ScheduleStartDeviceManager(const sptr<IRemoteObject>& appProxy, int32_t token,
const std::shared_ptr<ContinuationExtraParams>& continuationExtraParams = nullptr) override;
int32_t OnDeviceConnect(int32_t token, const std::vector<ContinuationResult>& continuationResults) override;
int32_t OnDeviceDisconnect(int32_t token, const std::vector<ContinuationResult>& continuationResults) override;
int32_t OnDeviceCancel() override;
};
} // namespace DistributedSchedule
} // namespace OHOS
#endif // OHOS_DISTRIBUTED_ABILITY_MANAGER_CONTINUATION_MANAGER_TEST_H

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Copyright (c) 2022-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
@ -15,7 +15,9 @@
#include "distributed_ability_manager_dumper_test.h"
#define private public
#include "distributed_ability_manager_dumper.h"
#undef private
#include "dtbschedmgr_log.h"
#include "nativetoken_kit.h"
#include "test_log.h"
@ -26,17 +28,11 @@ namespace DistributedSchedule {
using namespace testing;
using namespace testing::ext;
namespace {
constexpr int32_t DISTRIBUTED_SCHED_SA_ID = 1401;
const char* HIDUMPER_PROCESS_NAME = "hidumper_service";
const char* DISTSCHED_PROCESS_NAME = "distributedsched";
const char* INVALID_PROCESS_NAME = "invalid_process";
bool g_mockResult = false;
}
static bool MockDistributedSchedDumpFunc(const std::vector<std::string>& args, std::string& result)
{
return g_mockResult;
}
static void MockProcess(const char* processName)
{
uint64_t tokenId;
@ -66,7 +62,7 @@ void DistributedAbilityManagerDumperTest::TearDownTestCase()
void DistributedAbilityManagerDumperTest::SetUp()
{
dtbabilitymgrService_ = new DistributedAbilityManagerService(DISTRIBUTED_SCHED_SA_ID, true);
dtbabilitymgrService_ = new DistributedAbilityManagerService();
MockProcess(HIDUMPER_PROCESS_NAME);
DTEST_LOG << "DistributedAbilityManagerDumperTest::SetUp" << std::endl;
}
@ -116,96 +112,6 @@ HWTEST_F(DistributedAbilityManagerDumperTest, Dump_002, TestSize.Level3)
DTEST_LOG << "ContinuationManagerTest Dump_002 end" << std::endl;
}
/**
* @tc.name: ProcessDistributedSchedDump_001
* @tc.desc: call ProcessDistributedSchedDump with distributed server not load.
* @tc.type: FUNC
* @tc.require: I5PUBK
*/
HWTEST_F(DistributedAbilityManagerDumperTest, ProcessDistributedSchedDump_001, TestSize.Level3)
{
DTEST_LOG << "ContinuationManagerTest ProcessDistributedSchedDump_001 start" << std::endl;
if (dtbabilitymgrService_ == nullptr) {
DTEST_LOG << "dtbabilitymgrService_ is nullptr" << std::endl;
return;
}
dtbabilitymgrService_->isLoaded_ = false;
dtbabilitymgrService_->distributedSchedDumpFunc_ = nullptr;
const std::vector<std::string> args;
std::string dumpResult;
bool result = dtbabilitymgrService_->ProcessDistributedSchedDump(args, dumpResult);
EXPECT_EQ(false, result);
DTEST_LOG << "ContinuationManagerTest ProcessDistributedSchedDump_001 end" << std::endl;
}
/**
* @tc.name: ProcessDistributedSchedDump_002
* @tc.desc: call ProcessDistributedSchedDump with distributedSchedDumpFunc_ is nullptr.
* @tc.type: FUNC
* @tc.require: I5PUBK
*/
HWTEST_F(DistributedAbilityManagerDumperTest, ProcessDistributedSchedDump_002, TestSize.Level3)
{
DTEST_LOG << "ContinuationManagerTest ProcessDistributedSchedDump_002 start" << std::endl;
if (dtbabilitymgrService_ == nullptr) {
DTEST_LOG << "dtbabilitymgrService_ is nullptr" << std::endl;
return;
}
dtbabilitymgrService_->isLoaded_ = true;
dtbabilitymgrService_->distributedSchedDumpFunc_ = nullptr;
const std::vector<std::string> args;
std::string dumpResult;
bool result = dtbabilitymgrService_->ProcessDistributedSchedDump(args, dumpResult);
EXPECT_EQ(false, result);
DTEST_LOG << "ContinuationManagerTest ProcessDistributedSchedDump_002 end" << std::endl;
}
/**
* @tc.name: ProcessDistributedSchedDump_003
* @tc.desc: call ProcessDistributedSchedDump with distributed server load.
* @tc.type: FUNC
* @tc.require: I5PUBK
*/
HWTEST_F(DistributedAbilityManagerDumperTest, ProcessDistributedSchedDump_003, TestSize.Level3)
{
DTEST_LOG << "ContinuationManagerTest ProcessDistributedSchedDump_003 start" << std::endl;
if (dtbabilitymgrService_ == nullptr) {
DTEST_LOG << "dtbabilitymgrService_ is nullptr" << std::endl;
return;
}
dtbabilitymgrService_->isLoaded_ = true;
g_mockResult = true;
dtbabilitymgrService_->distributedSchedDumpFunc_ = &MockDistributedSchedDumpFunc;
const std::vector<std::string> args;
std::string dumpResult;
bool result = dtbabilitymgrService_->ProcessDistributedSchedDump(args, dumpResult);
EXPECT_EQ(true, result);
DTEST_LOG << "ContinuationManagerTest ProcessDistributedSchedDump_003 end" << std::endl;
}
/**
* @tc.name: ProcessDistributedSchedDump_004
* @tc.desc: call ProcessDistributedSchedDump with distributed server load.
* @tc.type: FUNC
* @tc.require: I5PUBK
*/
HWTEST_F(DistributedAbilityManagerDumperTest, ProcessDistributedSchedDump_004, TestSize.Level3)
{
DTEST_LOG << "ContinuationManagerTest ProcessDistributedSchedDump_004 start" << std::endl;
if (dtbabilitymgrService_ == nullptr) {
DTEST_LOG << "dtbabilitymgrService_ is nullptr" << std::endl;
return;
}
dtbabilitymgrService_->isLoaded_ = true;
g_mockResult = false;
dtbabilitymgrService_->distributedSchedDumpFunc_ = &MockDistributedSchedDumpFunc;
const std::vector<std::string> args;
std::string dumpResult;
bool result = dtbabilitymgrService_->ProcessDistributedSchedDump(args, dumpResult);
EXPECT_EQ(false, result);
DTEST_LOG << "ContinuationManagerTest ProcessDistributedSchedDump_004 end" << std::endl;
}
/**
* @tc.name: Dumper_Dump_001
* @tc.desc: call DistributedAbilityManagerDumper::Dump not from hidumper.
@ -222,7 +128,7 @@ HWTEST_F(DistributedAbilityManagerDumperTest, Dumper_Dump_001, TestSize.Level3)
MockProcess(DISTSCHED_PROCESS_NAME);
const std::vector<std::string> args;
std::string dumpResult;
bool result = DistributedAbilityManagerDumper::Dump(dtbabilitymgrService_, args, dumpResult);
bool result = DistributedAbilityManagerDumper::Dump(args, dumpResult);
EXPECT_EQ(false, result);
DTEST_LOG << "ContinuationManagerTest Dumper_Dump_001 end" << std::endl;
}
@ -240,12 +146,9 @@ HWTEST_F(DistributedAbilityManagerDumperTest, Dumper_Dump_002, TestSize.Level3)
DTEST_LOG << "dtbabilitymgrService_ is nullptr" << std::endl;
return;
}
dtbabilitymgrService_->isLoaded_ = true;
g_mockResult = true;
dtbabilitymgrService_->distributedSchedDumpFunc_ = &MockDistributedSchedDumpFunc;
const std::vector<std::string> args;
std::string dumpResult;
bool result = DistributedAbilityManagerDumper::Dump(dtbabilitymgrService_, args, dumpResult);
bool result = DistributedAbilityManagerDumper::Dump(args, dumpResult);
EXPECT_EQ(true, result);
DTEST_LOG << "ContinuationManagerTest Dumper_Dump_002 end" << std::endl;
}
@ -263,19 +166,16 @@ HWTEST_F(DistributedAbilityManagerDumperTest, Dumper_Dump_003, TestSize.Level3)
DTEST_LOG << "dtbabilitymgrService_ is nullptr" << std::endl;
return;
}
dtbabilitymgrService_->isLoaded_ = true;
g_mockResult = true;
dtbabilitymgrService_->distributedSchedDumpFunc_ = &MockDistributedSchedDumpFunc;
const std::vector<std::string> args = {"-h"};
std::string dumpResult;
bool result = DistributedAbilityManagerDumper::Dump(dtbabilitymgrService_, args, dumpResult);
bool result = DistributedAbilityManagerDumper::Dump(args, dumpResult);
EXPECT_EQ(true, result);
DTEST_LOG << "ContinuationManagerTest Dumper_Dump_003 end" << std::endl;
}
/**
* @tc.name: Dumper_Dump_004
* @tc.desc: call DistributedAbilityManagerDumper::Dump with args -connect.
* @tc.desc: call DistributedAbilityManagerDumper::Dump with args -register.
* @tc.type: FUNC
* @tc.require: I5PUBK
*/
@ -286,12 +186,9 @@ HWTEST_F(DistributedAbilityManagerDumperTest, Dumper_Dump_004, TestSize.Level3)
DTEST_LOG << "dtbabilitymgrService_ is nullptr" << std::endl;
return;
}
dtbabilitymgrService_->isLoaded_ = true;
g_mockResult = true;
dtbabilitymgrService_->distributedSchedDumpFunc_ = &MockDistributedSchedDumpFunc;
const std::vector<std::string> args = {"-connect"};
const std::vector<std::string> args = {"-register"};
std::string dumpResult;
bool result = DistributedAbilityManagerDumper::Dump(dtbabilitymgrService_, args, dumpResult);
bool result = DistributedAbilityManagerDumper::Dump(args, dumpResult);
EXPECT_EQ(true, result);
DTEST_LOG << "ContinuationManagerTest Dumper_Dump_004 end" << std::endl;
}
@ -309,12 +206,9 @@ HWTEST_F(DistributedAbilityManagerDumperTest, Dumper_Dump_005, TestSize.Level3)
DTEST_LOG << "dtbabilitymgrService_ is nullptr" << std::endl;
return;
}
dtbabilitymgrService_->isLoaded_ = true;
g_mockResult = true;
dtbabilitymgrService_->distributedSchedDumpFunc_ = &MockDistributedSchedDumpFunc;
const std::vector<std::string> args = {"-mockArgs"};
std::string dumpResult;
bool result = DistributedAbilityManagerDumper::Dump(dtbabilitymgrService_, args, dumpResult);
bool result = DistributedAbilityManagerDumper::Dump(args, dumpResult);
EXPECT_EQ(false, result);
DTEST_LOG << "ContinuationManagerTest Dumper_Dump_005 end" << std::endl;
DTEST_LOG << dumpResult << std::endl;
@ -322,32 +216,13 @@ HWTEST_F(DistributedAbilityManagerDumperTest, Dumper_Dump_005, TestSize.Level3)
/**
* @tc.name: Dumper_Dump_006
* @tc.desc: call DistributedAbilityManagerDumper::Dump with dmsDumper is nullptr.
* @tc.desc: call DistributedAbilityManagerDumper::Dump from invalid process.
* @tc.type: FUNC
* @tc.require: I5PUBK
*/
HWTEST_F(DistributedAbilityManagerDumperTest, Dumper_Dump_006, TestSize.Level4)
{
DTEST_LOG << "ContinuationManagerTest Dumper_Dump_006 start" << std::endl;
dtbabilitymgrService_->isLoaded_ = true;
g_mockResult = true;
dtbabilitymgrService_->distributedSchedDumpFunc_ = &MockDistributedSchedDumpFunc;
const std::vector<std::string> args;
std::string dumpResult;
bool result = DistributedAbilityManagerDumper::Dump(nullptr, args, dumpResult);
EXPECT_EQ(false, result);
DTEST_LOG << "ContinuationManagerTest Dumper_Dump_006 end" << std::endl;
}
/**
* @tc.name: Dumper_Dump_007
* @tc.desc: call DistributedAbilityManagerDumper::Dump from invalid process.
* @tc.type: FUNC
* @tc.require: I5PUBK
*/
HWTEST_F(DistributedAbilityManagerDumperTest, Dumper_Dump_007, TestSize.Level4)
{
DTEST_LOG << "ContinuationManagerTest Dumper_Dump_007 start" << std::endl;
if (dtbabilitymgrService_ == nullptr) {
DTEST_LOG << "dtbabilitymgrService_ is nullptr" << std::endl;
return;
@ -355,9 +230,45 @@ HWTEST_F(DistributedAbilityManagerDumperTest, Dumper_Dump_007, TestSize.Level4)
MockProcess(INVALID_PROCESS_NAME);
const std::vector<std::string> args;
std::string dumpResult;
bool result = DistributedAbilityManagerDumper::Dump(dtbabilitymgrService_, args, dumpResult);
bool result = DistributedAbilityManagerDumper::Dump(args, dumpResult);
EXPECT_EQ(false, result);
DTEST_LOG << "ContinuationManagerTest Dumper_Dump_007 end" << std::endl;
DTEST_LOG << "ContinuationManagerTest Dumper_Dump_006 end" << std::endl;
}
/**
* @tc.name: Dumper_DumpDefault_001
* @tc.desc: call DistributedAbilityManagerDumper::DumpDefault.
* @tc.type: FUNC
*/
HWTEST_F(DistributedAbilityManagerDumperTest, Dumper_DumpDefault_001, TestSize.Level4)
{
DTEST_LOG << "ContinuationManagerTest Dumper_DumpDefault_001 start" << std::endl;
if (dtbabilitymgrService_ == nullptr) {
DTEST_LOG << "dtbabilitymgrService_ is nullptr" << std::endl;
return;
}
std::string dumpResult;
bool result = DistributedAbilityManagerDumper::DumpDefault(dumpResult);
EXPECT_EQ(true, result);
DTEST_LOG << "ContinuationManagerTest Dumper_DumpDefault_001 end" << std::endl;
}
/**
* @tc.name: Dumper_ShowAppRegisterInfo_001
* @tc.desc: call DistributedAbilityManagerDumper::ShowAppRegisterInfo.
* @tc.type: FUNC
*/
HWTEST_F(DistributedAbilityManagerDumperTest, Dumper_ShowAppRegisterInfo_001, TestSize.Level4)
{
DTEST_LOG << "ContinuationManagerTest Dumper_ShowAppRegisterInfo_001 start" << std::endl;
if (dtbabilitymgrService_ == nullptr) {
DTEST_LOG << "dtbabilitymgrService_ is nullptr" << std::endl;
return;
}
std::string dumpResult;
DistributedAbilityManagerDumper::ShowAppRegisterInfo(dumpResult);
EXPECT_EQ(false, dumpResult.empty());
DTEST_LOG << "ContinuationManagerTest Dumper_ShowAppRegisterInfo_001 end" << std::endl;
}
} // namespace DistributedSchedule
} // namespace OHOS

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Copyright (c) 2022-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
@ -16,7 +16,6 @@
#include <thread>
#include "distributed_sched_util.h"
#include "dms_notifier.h"
#include "dtbschedmgr_log.h"
#define private public
#include "mission/distributed_sched_mission_manager.h"
@ -29,90 +28,33 @@ using namespace testing::ext;
namespace OHOS {
namespace DistributedSchedule {
namespace {
constexpr int32_t DISTRIBUTED_SCHED_SA_ID = 1401;
constexpr int32_t GET_DISTRIBUTED_COMPONENT_LIST_REQUEST_CODE = 161;
constexpr int32_t REGISTER = 500;
constexpr int32_t UPDATE_CONNECT_STATUS = 504;
constexpr int32_t INVALID_CODE = -1;
constexpr int32_t MAX_WAIT_TIME = 10000;
const std::u16string DMS_STUB_INTERFACE_TOKEN = u"ohos.distributedschedule.accessToken";
const std::u16string DMS_STUB_INTERFACE_TOKEN = u"OHOS.DistributedSchedule.IDistributedAbilityManager";
const std::string DEVICE_ID = "testDeviceId";
}
sptr<DistributedAbilityManagerService> DistributedAbilityManagerServiceTest::dtbabilitymgrService_;
int32_t DistributedAbilityManagerServiceTest::startTaskNum_ = 2;
int32_t DistributedAbilityManagerServiceTest::startTaskNum_ = 1;
std::mutex DistributedAbilityManagerServiceTest::caseDoneLock_;
std::condition_variable DistributedAbilityManagerServiceTest::caseDoneCondition_;
class MockDmsNotifier : public DmsNotifier {
public:
MockDmsNotifier() = default;
~MockDmsNotifier() = default;
void DeviceOnlineNotify(const std::string& deviceId) override;
void DeviceOfflineNotify(const std::string& deviceId) override;
void ProcessNotifierDied(const sptr<IRemoteObject>& notifier) override;
void ScheduleStartDeviceManager(const sptr<IRemoteObject>& appProxy, int32_t token,
const std::shared_ptr<ContinuationExtraParams>& continuationExtraParams = nullptr) override;
int32_t OnDeviceConnect(int32_t token, const std::vector<ContinuationResult>& continuationResults) override;
int32_t OnDeviceDisconnect(int32_t token, const std::vector<ContinuationResult>& continuationResults) override;
int32_t OnDeviceCancel() override;
};
void MockDmsNotifier::DeviceOnlineNotify(const std::string& deviceId)
{
}
void MockDmsNotifier::DeviceOfflineNotify(const std::string& deviceId)
{
}
void MockDmsNotifier::ProcessNotifierDied(const sptr<IRemoteObject>& notifier)
{
}
void MockDmsNotifier::ScheduleStartDeviceManager(const sptr<IRemoteObject>& appProxy, int32_t token,
const std::shared_ptr<ContinuationExtraParams>& continuationExtraParams)
{
}
int32_t MockDmsNotifier::OnDeviceConnect(int32_t token,
const std::vector<ContinuationResult>& continuationResults)
{
return 0;
}
int32_t MockDmsNotifier::OnDeviceDisconnect(int32_t token,
const std::vector<ContinuationResult>& continuationResults)
{
return 0;
}
int32_t MockDmsNotifier::OnDeviceCancel()
{
return 0;
}
void DistributedAbilityManagerServiceTest::SetUpTestCase()
{
dtbabilitymgrService_ = new DistributedAbilityManagerService(DISTRIBUTED_SCHED_SA_ID, true);
dtbabilitymgrService_ = new DistributedAbilityManagerService();
DTEST_LOG << "DistributedAbilityManagerServiceTest::SetUpTestCase" << std::endl;
}
void DistributedAbilityManagerServiceTest::TearDownTestCase()
{
// Wait until all asyn tasks are completed before exiting the test suite
// Wait until all async tasks are completed before exiting the test suite
auto caseDoneNotifyTask = []() {
std::lock_guard<std::mutex> autoLock(caseDoneLock_);
--startTaskNum_;
caseDoneCondition_.notify_one();
};
if (DistributedSchedMissionManager::GetInstance().distributedDataStorage_ != nullptr) {
std::shared_ptr<AppExecFwk::EventHandler> dmsDataStorageHandler =
DistributedSchedMissionManager::GetInstance().distributedDataStorage_->dmsDataStorageHandler_;
if (dmsDataStorageHandler != nullptr) {
dmsDataStorageHandler->PostTask(caseDoneNotifyTask);
}
}
if (dtbabilitymgrService_->continuationHandler_ != nullptr) {
dtbabilitymgrService_->continuationHandler_->PostTask(caseDoneNotifyTask);
}
@ -132,103 +74,9 @@ void DistributedAbilityManagerServiceTest::TearDown()
DTEST_LOG << "DistributedAbilityManagerServiceTest::TearDown" << std::endl;
}
/**
* @tc.name: IsDistributedSchedLoaded_001
* @tc.desc: test IsDistributedSchedLoaded
* @tc.type: FUNC
* @tc.require: I5NOA1
*/
HWTEST_F(DistributedAbilityManagerServiceTest, IsDistributedSchedLoaded_001, TestSize.Level3)
{
DTEST_LOG << "DistributedAbilityManagerServiceTest IsDistributedSchedLoaded_001 start" << std::endl;
if (dtbabilitymgrService_ == nullptr) {
DTEST_LOG << "dtbabilitymgrService_ is nullptr" << std::endl;
return;
}
int32_t result = dtbabilitymgrService_->IsDistributedSchedLoaded();
EXPECT_EQ(false, result);
DTEST_LOG << "DistributedAbilityManagerServiceTest IsDistributedSchedLoaded_001 end" << std::endl;
}
/**
* @tc.name: GetDistributedComponentListInner_001
* @tc.desc: test GetDistributedComponentListInner when dms not start
* @tc.type: FUNC
* @tc.require: I5NOA1
*/
HWTEST_F(DistributedAbilityManagerServiceTest, GetDistributedComponentListInner_001, TestSize.Level3)
{
DTEST_LOG << "DistributedAbilityManagerServiceTest GetDistributedComponentListInner_001 start" << std::endl;
if (dtbabilitymgrService_ == nullptr) {
DTEST_LOG << "dtbabilitymgrService_ is nullptr" << std::endl;
return;
}
MessageParcel data;
MessageParcel reply;
MessageOption option;
data.WriteInterfaceToken(DMS_STUB_INTERFACE_TOKEN);
int32_t result = dtbabilitymgrService_->GetDistributedComponentListInner(data, reply, option);
EXPECT_EQ(ERR_NONE, result);
result = reply.ReadInt32();
EXPECT_EQ(ERR_NONE, result);
std::vector<std::string> distributedComponents;
reply.ReadStringVector(&distributedComponents);
EXPECT_EQ(true, distributedComponents.empty());
DTEST_LOG << "DistributedAbilityManagerServiceTest GetDistributedComponentListInner_001 end" << std::endl;
}
/**
* @tc.name: GetDistributedComponentListInner_002
* @tc.desc: test GetDistributedComponentListInner when isLoaded_ true
* @tc.type: FUNC
* @tc.require: I5NOA1
*/
HWTEST_F(DistributedAbilityManagerServiceTest, GetDistributedComponentListInner_002, TestSize.Level3)
{
DTEST_LOG << "DistributedAbilityManagerServiceTest GetDistributedComponentListInner_002 start" << std::endl;
if (dtbabilitymgrService_ == nullptr) {
DTEST_LOG << "dtbabilitymgrService_ is nullptr" << std::endl;
return;
}
MessageParcel data;
MessageParcel reply;
MessageOption option;
data.WriteInterfaceToken(DMS_STUB_INTERFACE_TOKEN);
bool result1 = dtbabilitymgrService_->InitDmsImplFunc();
EXPECT_EQ(true, result1);
int32_t result2 = dtbabilitymgrService_->GetDistributedComponentListInner(data, reply, option);
EXPECT_EQ(ERR_NONE, result2);
result2 = reply.ReadInt32();
EXPECT_EQ(ERR_NONE, result2);
std::vector<std::string> distributedComponents;
reply.ReadStringVector(&distributedComponents);
EXPECT_EQ(true, distributedComponents.empty());
DTEST_LOG << "DistributedAbilityManagerServiceTest GetDistributedComponentListInner_002 end" << std::endl;
}
/**
* @tc.name: GetDistributedComponentListInner_003
* @tc.desc: test GetDistributedComponentListInner with invalid token
* @tc.type: FUNC
* @tc.require: I5NOA1
*/
HWTEST_F(DistributedAbilityManagerServiceTest, GetDistributedComponentListInner_003, TestSize.Level3)
{
DTEST_LOG << "DistributedAbilityManagerServiceTest GetDistributedComponentListInner_003 start" << std::endl;
if (dtbabilitymgrService_ == nullptr) {
DTEST_LOG << "dtbabilitymgrService_ is nullptr" << std::endl;
return;
}
MessageParcel data;
MessageParcel reply;
MessageOption option;
int32_t result = dtbabilitymgrService_->GetDistributedComponentListInner(data, reply, option);
EXPECT_EQ(DMS_PERMISSION_DENIED, result);
DTEST_LOG << "DistributedAbilityManagerServiceTest GetDistributedComponentListInner_003 end" << std::endl;
}
/**
* @tc.name: OnRemoteRequest_001
* @tc.desc: test OnRemoteRequest to start GetDistributedComponentListInner
* @tc.desc: test OnRemoteRequest to start Register
* @tc.type: FUNC
* @tc.require: I5NOA1
*/
@ -243,9 +91,8 @@ HWTEST_F(DistributedAbilityManagerServiceTest, OnRemoteRequest_001, TestSize.Lev
MessageParcel reply;
MessageOption option;
data.WriteInterfaceToken(DMS_STUB_INTERFACE_TOKEN);
int32_t result = dtbabilitymgrService_->OnRemoteRequest(
GET_DISTRIBUTED_COMPONENT_LIST_REQUEST_CODE, data, reply, option);
EXPECT_EQ(ERR_NONE, result);
int32_t result = dtbabilitymgrService_->OnRemoteRequest(REGISTER, data, reply, option);
EXPECT_EQ(DMS_PERMISSION_DENIED, result);
DTEST_LOG << "DistributedAbilityManagerServiceTest OnRemoteRequest_001 end" << std::endl;
}
@ -336,40 +183,6 @@ HWTEST_F(DistributedAbilityManagerServiceTest, OnRemoteRequest_005, TestSize.Lev
DTEST_LOG << "DistributedAbilityManagerServiceTest OnRemoteRequest_005 end" << std::endl;
}
/**
* @tc.name: DeviceOnlineNotify
* @tc.desc: test DeviceOnlineNotify
* @tc.type: FUNC
*/
HWTEST_F(DistributedAbilityManagerServiceTest, DeviceOnlineNotify_001, TestSize.Level3)
{
DTEST_LOG << "DistributedAbilityManagerServiceTest DeviceOnlineNotify_001 start" << std::endl;
if (dtbabilitymgrService_ == nullptr) {
DTEST_LOG << "dtbabilitymgrService_ is nullptr" << std::endl;
return;
}
dtbabilitymgrService_->InitDmsImplFunc();
EXPECT_EQ(dtbabilitymgrService_->isLoaded_, true);
dtbabilitymgrService_->DeviceOnlineNotify(DEVICE_ID);
DTEST_LOG << "DistributedAbilityManagerServiceTest DeviceOnlineNotify_001 end" << std::endl;
}
/**
* @tc.name: DeviceOfflineNotify
* @tc.desc: test DeviceOfflineNotify
* @tc.type: FUNC
*/
HWTEST_F(DistributedAbilityManagerServiceTest, DeviceOfflineNotify_001, TestSize.Level3)
{
DTEST_LOG << "DistributedAbilityManagerServiceTest DeviceOfflineNotify_001 start" << std::endl;
if (dtbabilitymgrService_ == nullptr) {
DTEST_LOG << "dtbabilitymgrService_ is nullptr" << std::endl;
return;
}
dtbabilitymgrService_->DeviceOfflineNotify(DEVICE_ID);
DTEST_LOG << "DistributedAbilityManagerServiceTest DeviceOfflineNotify_001 end" << std::endl;
}
/**
* @tc.name: ConnectAbility
* @tc.desc: test ConnectAbility
@ -382,10 +195,8 @@ HWTEST_F(DistributedAbilityManagerServiceTest, ConnectAbility_001, TestSize.Leve
DTEST_LOG << "dtbabilitymgrService_ is nullptr" << std::endl;
return;
}
EXPECT_EQ(dtbabilitymgrService_->isLoaded_, true);
sptr<DmsNotifier> dmsNotifier(new MockDmsNotifier());
std::shared_ptr<ContinuationExtraParams> continuationExtraParams = std::make_shared<ContinuationExtraParams>();
int32_t ret = dtbabilitymgrService_->ConnectAbility(dmsNotifier, 1, continuationExtraParams);
int32_t ret = dtbabilitymgrService_->ConnectAbility(1, continuationExtraParams);
EXPECT_NE(ret, true);
DTEST_LOG << "DistributedAbilityManagerServiceTest ConnectAbility_001 end" << std::endl;
}

View File

@ -34,7 +34,7 @@ public:
static int32_t startTaskNum_;
static std::mutex caseDoneLock_;
static std::condition_variable caseDoneCondition_;
static sptr<DistributedAbilityManagerService> dtbabilitymgrService_;
static sptr<DistributedAbilityManagerService> dtbabilitymgrService_;
};
} // namespace DistributedSchedule
} // namespace OHOS

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Copyright (c) 2022-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
@ -23,9 +23,9 @@ using namespace testing::ext;
namespace OHOS {
namespace DistributedSchedule {
namespace {
constexpr int32_t DISTRIBUTED_SCHED_SA_ID = 1401;
constexpr int32_t REQUEST_CODE_ERR = 305;
constexpr int32_t INVALID_CODE = 123456;
const std::u16string DMS_PROXY_INTERFACE_TOKEN = u"ohos.distributedschedule.accessToken";
const std::u16string DMS_PROXY_INTERFACE_TOKEN = u"OHOS.DistributedSchedule.IDistributedAbilityManager";
}
void DistributedAbilityManagerStubTest::SetUpTestCase()
@ -40,7 +40,7 @@ void DistributedAbilityManagerStubTest::TearDownTestCase()
void DistributedAbilityManagerStubTest::SetUp()
{
dtbabilitymgrStub_ = new DistributedAbilityManagerService(DISTRIBUTED_SCHED_SA_ID, true);
dtbabilitymgrStub_ = new DistributedAbilityManagerService();
DTEST_LOG << "DistributedAbilityManagerStubTest::SetUp" << std::endl;
}
@ -78,14 +78,12 @@ HWTEST_F(DistributedAbilityManagerStubTest, OnRemoteRequest_001, TestSize.Level3
HWTEST_F(DistributedAbilityManagerStubTest, OnRemoteRequest_002, TestSize.Level3)
{
DTEST_LOG << "DistributedAbilityManagerStubTest OnRemoteRequest_002 start" << std::endl;
uint32_t code = INVALID_CODE;
MessageParcel data;
MessageParcel reply;
MessageOption option;
dtbabilitymgrStub_->distributedFuncMap_[INVALID_CODE] = nullptr;
data.WriteInterfaceToken(DMS_PROXY_INTERFACE_TOKEN);
int32_t result = dtbabilitymgrStub_->OnRemoteRequest(code, data, reply, option);
EXPECT_EQ(result, ERR_NULL_OBJECT);
int32_t result = dtbabilitymgrStub_->OnRemoteRequest(INVALID_CODE, data, reply, option);
EXPECT_EQ(result, REQUEST_CODE_ERR);
DTEST_LOG << "DistributedAbilityManagerStubTest OnRemoteRequest_002 end" << std::endl;
}
@ -185,22 +183,5 @@ HWTEST_F(DistributedAbilityManagerStubTest, StartDeviceManagerInner_001, TestSiz
EXPECT_EQ(result, ERR_NULL_OBJECT);
DTEST_LOG << "DistributedAbilityManagerStubTest StartDeviceManagerInner_001 end" << std::endl;
}
/**
* @tc.name: GetDistributedComponentListInner_001
* @tc.desc: test GetDistributedComponentListInner with interfaceToken is empty
* @tc.type: FUNC
* @tc.require: I64FU7
*/
HWTEST_F(DistributedAbilityManagerStubTest, GetDistributedComponentListInner_001, TestSize.Level3)
{
DTEST_LOG << "DistributedAbilityManagerStubTest GetDistributedComponentListInner_001 start" << std::endl;
MessageParcel data;
MessageParcel reply;
MessageOption option;
int32_t result = dtbabilitymgrStub_->GetDistributedComponentListInner(data, reply, option);
EXPECT_EQ(result, DMS_PERMISSION_DENIED);
DTEST_LOG << "DistributedAbilityManagerStubTest GetDistributedComponentListInner_001 end" << std::endl;
}
}
}

View File

@ -43,10 +43,14 @@ ohos_shared_library("distributedschedsvr") {
sources = [
"src/ability_connection_wrapper_proxy.cpp",
"src/ability_connection_wrapper_stub.cpp",
"src/app_connection_stub.cpp",
"src/adapter/dnetwork_adapter.cpp",
"src/bundle/bundle_manager_callback_stub.cpp",
"src/bundle/bundle_manager_internal.cpp",
"src/connect_death_recipient.cpp",
"src/deviceManager/dms_device_info.cpp",
"src/dfx/dms_hisysevent_report.cpp",
"src/dfx/dms_hitrace_chain.cpp",
"src/distributed_device_node_listener.cpp",
"src/distributed_sched_adapter.cpp",
"src/distributed_sched_continuation.cpp",
"src/distributed_sched_dumper.cpp",
@ -59,6 +63,8 @@ ohos_shared_library("distributedschedsvr") {
"src/dms_free_install_callback_proxy.cpp",
"src/dms_free_install_callback_stub.cpp",
"src/dms_token_callback.cpp",
"src/dms_version_manager.cpp",
"src/dtbschedmgr_device_info_storage.cpp",
]
configs = [
@ -74,8 +80,10 @@ ohos_shared_library("distributedschedsvr") {
"bundle_framework:appexecfwk_core",
"c_utils:utils",
"device_auth:deviceauth_sdk",
"device_info_manager:distributed_device_profile_client",
"device_manager:devicemanagersdk",
"eventhandler:libeventhandler",
"hisysevent_native:libhisysevent",
"hitrace_native:hitrace_meter",
"hitrace_native:libhitracechain",
"hiviewdfx_hilog_native:libhilog",
@ -91,8 +99,6 @@ ohos_shared_library("distributedschedsvr") {
external_deps += [ "efficiency_manager:suspend_manager_client" ]
}
deps = [ "//foundation/ability/dmsfwk/services/base:dmsbaseinner" ]
if (dmsfwk_standard_form_share) {
external_deps += [ "form_fwk:form_manager" ]
sources += [ "src/form_mgr_death_recipient.cpp" ]

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* Copyright (c) 2021-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
@ -67,6 +67,7 @@ public:
private:
DISALLOW_COPY_AND_MOVE(DnetworkAdapter);
bool UpdateDeviceInfoStorage();
static std::shared_ptr<AppExecFwk::EventHandler> dnetworkHandler_;
static std::mutex listenerSetMutex_;

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* Copyright (c) 2021-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

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Copyright (c) 2022-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

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Copyright (c) 2022-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

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Copyright (c) 2022-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

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* Copyright (c) 2021-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

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* Copyright (c) 2021-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
@ -24,16 +24,15 @@ namespace DistributedSchedule {
class DistributedSchedDumper {
public:
static bool Dump(const std::vector<std::string>& args, std::string& result);
private:
DistributedSchedDumper() = default;
~DistributedSchedDumper() = default;
static void ShowHelp(std::string& result);
static void IllegalInput(std::string& result);
static void ShowConnectRemoteAbility(std::string& result);
static bool CanDump();
static bool DumpDefault(std::string& result);
static void ShowConnectRemoteAbility(std::string& result);
static void ShowHelp(std::string& result);
static void IllegalInput(std::string& result);
};
} // namespace DistributedSchedule
} // namespace OHOS

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2021-2022 Huawei Device Co., Ltd.
* Copyright (c) 2021-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
@ -21,11 +21,9 @@
#include <set>
#include <unordered_map>
#include "continuation_extra_params.h"
#include "distributed_sched_stub.h"
#include "distributed_sched_continuation.h"
#include "dms_callback_task.h"
#include "dms_notifier.h"
#ifdef SUPPORT_DISTRIBUTED_FORM_SHARE
#include "form_mgr_interface.h"
#endif
@ -36,6 +34,7 @@
#include "nocopyable.h"
#endif
#include "single_instance.h"
#include "system_ability.h"
namespace OHOS {
namespace DistributedSchedule {
@ -62,13 +61,18 @@ struct ProcessDiedNotifyInfo {
TargetComponent targetComponent;
};
class DistributedSchedService : public DistributedSchedStub {
DECLARE_SINGLE_INSTANCE_BASE(DistributedSchedService);
class DistributedSchedService : public SystemAbility, public DistributedSchedStub {
DECLARE_SYSTEM_ABILITY(DistributedSchedService);
DECLARE_SINGLE_INSTANCE_BASE(DistributedSchedService);
public:
~DistributedSchedService() = default;
void OnStart();
void OnStart() override;
void OnStop() override;
int32_t Dump(int32_t fd, const std::vector<std::u16string>& args) override;
void DeviceOnlineNotify(const std::string& deviceId);
void DeviceOfflineNotify(const std::string& deviceId);
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,
@ -98,13 +102,6 @@ public:
std::vector<AAFwk::MissionInfo>& missionInfos) override;
int32_t NotifyMissionsChangedFromRemote(const std::vector<DstbMissionInfo>& missionInfos,
const CallerInfo& callerInfo) override;
#endif
void ProcessConnectDied(const sptr<IRemoteObject>& connect);
void ProcessDeviceOffline(const std::string& deviceId);
void DumpConnectInfo(std::string& info);
void DumpSessionsLocked(const std::list<ConnectAbilitySession>& sessionsList, std::string& info);
void DumpElementLocked(const std::list<AppExecFwk::ElementName>& elementsList, std::string& info);
#ifdef SUPPORT_DISTRIBUTED_MISSION_MANAGER
int32_t GetRemoteMissionSnapshotInfo(const std::string& networkId, int32_t missionId,
std::unique_ptr<AAFwk::MissionSnapshot>& missionSnapshot) override;
int32_t StartSyncRemoteMissions(const std::string& devId, bool fixConflict, int64_t tag) override;
@ -115,6 +112,11 @@ public:
int32_t RegisterMissionListener(const std::u16string& devId, const sptr<IRemoteObject>& obj) override;
int32_t UnRegisterMissionListener(const std::u16string& devId, const sptr<IRemoteObject>& obj) override;
#endif
void ProcessConnectDied(const sptr<IRemoteObject>& connect);
void ProcessDeviceOffline(const std::string& deviceId);
void DumpConnectInfo(std::string& info);
void DumpSessionsLocked(const std::list<ConnectAbilitySession>& sessionsList, std::string& info);
void DumpElementLocked(const std::list<AppExecFwk::ElementName>& elementsList, std::string& info);
int32_t StartRemoteAbilityByCall(const OHOS::AAFwk::Want& want, const sptr<IRemoteObject>& connect,
int32_t callerUid, int32_t callerPid, uint32_t accessToken) override;
int32_t ReleaseRemoteAbility(const sptr<IRemoteObject>& connect,
@ -141,10 +143,6 @@ public:
void SetContinuationTimeout(int32_t missionId, int32_t timeout);
void RemoveContinuationTimeout(int32_t missionId);
std::string GetContinuaitonDevice(int32_t missionId);
int32_t ConnectAbility(const sptr<DmsNotifier>& dmsNotifier, int32_t token,
const std::shared_ptr<ContinuationExtraParams>& continuationExtraParams);
int32_t DisconnectAbility();
private:
DistributedSchedService();
bool Init();
@ -220,7 +218,6 @@ private:
std::mutex callerLock_;
std::map<sptr<IRemoteObject>, std::list<ConnectAbilitySession>> callerMap_;
sptr<IRemoteObject::DeathRecipient> callerDeathRecipientForLocalDevice_;
sptr<IRemoteObject> connect_;
};
class ConnectAbilitySession {

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Copyright (c) 2022-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
@ -20,14 +20,6 @@
namespace OHOS {
namespace DistributedSchedule {
#define IN_PROCESS_CALL(theCall) \
([&]() { \
std::string identity = IPCSkeleton::ResetCallingIdentity(); \
auto retVal = theCall; \
IPCSkeleton::SetCallingIdentity(identity); \
return retVal; \
}())
struct DmsVersion {
uint32_t majorVersionNum = 0;
uint32_t minorVersionNum = 0;

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2021-2022 Huawei Device Co., Ltd.
* Copyright (c) 2021-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
@ -21,7 +21,6 @@
#include "adapter/dnetwork_adapter.h"
#include "deviceManager/dms_device_info.h"
#include "distributed_device_node_listener.h"
#include "dms_notifier.h"
#include "event_handler.h"
#include "iremote_object.h"
#include "single_instance.h"
@ -40,7 +39,6 @@ class DtbschedmgrDeviceInfoStorage {
public:
bool Init();
bool Init(const sptr<DmsNotifier>& listener);
void Stop();
bool GetLocalDeviceId(std::string& deviceId);
void DeviceOnlineNotify(const std::shared_ptr<DmsDeviceInfo> devInfo);
@ -76,6 +74,13 @@ public:
*/
void GetDeviceIdSet(std::set<std::string>& deviceIdSet);
/**
* UpdateDeviceInfoStorage update device Info cache
*
* @param dmDeviceInfoList
*/
void UpdateDeviceInfoStorage(const std::vector<DistributedHardware::DmDeviceInfo>& dmDeviceInfoList);
private:
bool InitNetworkIdManager(std::shared_ptr<DnetworkAdapter> dnetworkAdapter);
bool ConnectSoftbus();
@ -84,7 +89,6 @@ private:
bool GetLocalDeviceFromDnet(std::string& deviceId);
void RegisterUuidNetworkIdMap(const std::string& networkId);
void UnregisterUuidNetworkIdMap(const std::string& networkId);
sptr<DmsNotifier> listener_;
std::mutex deviceLock_;
std::shared_ptr<DistributedDeviceNodeListener> deviceNodeListener_;
std::map<std::string, std::shared_ptr<DmsDeviceInfo>> remoteDevices_;

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2021-2022 Huawei Device Co., Ltd.
* Copyright (c) 2021-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

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* Copyright (c) 2021-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

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* Copyright (c) 2021-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
@ -110,7 +110,6 @@ bool DnetworkAdapter::AddDeviceChangeListener(const std::shared_ptr<DeviceListen
HILOGE("handler is null");
return false;
}
{
std::lock_guard<std::mutex> autoLock(listenerSetMutex_);
if (listenerSet_.find(listener) == listenerSet_.end()) {
@ -120,7 +119,6 @@ bool DnetworkAdapter::AddDeviceChangeListener(const std::shared_ptr<DeviceListen
return true;
}
}
auto registerTask = [this]() {
HILOGD("AddDeviceChangeListener register mission...");
int32_t retryTimes = 0;
@ -132,16 +130,17 @@ bool DnetworkAdapter::AddDeviceChangeListener(const std::shared_ptr<DeviceListen
std::this_thread::sleep_for(1s);
continue;
}
errCode = DeviceManager::GetInstance().RegisterDevStateCallback(PKG_NAME, "", stateCallback_);
if (errCode == ERR_OK) {
if (errCode != ERR_OK) {
HILOGD("AddDeviceChangeListener Reg errCode = %{public}d, retrying...", errCode);
errCode = DeviceManager::GetInstance().UnRegisterDevStateCallback(PKG_NAME);
HILOGD("AddDeviceChangeListener Unreg errCode = %{public}d", errCode);
std::this_thread::sleep_for(1s);
continue;
}
if (UpdateDeviceInfoStorage()) {
break;
}
HILOGD("AddDeviceChangeListener Reg errCode = %{public}d, retrying...", errCode);
errCode = DeviceManager::GetInstance().UnRegisterDevStateCallback(PKG_NAME);
HILOGD("AddDeviceChangeListener Unreg errCode = %{public}d", errCode);
std::this_thread::sleep_for(1s);
}
HILOGI("AddDeviceChangeListener %{public}s", (errCode == ERR_OK) ? "success" : "timeout");
};
@ -152,6 +151,19 @@ bool DnetworkAdapter::AddDeviceChangeListener(const std::shared_ptr<DeviceListen
return true;
}
bool DnetworkAdapter::UpdateDeviceInfoStorage()
{
std::vector<DistributedHardware::DmDeviceInfo> dmDeviceInfoList;
int32_t errCode = DeviceManager::GetInstance().GetTrustedDeviceList(PKG_NAME, "", dmDeviceInfoList);
if (errCode != ERR_OK) {
HILOGE("GetTrustedDeviceList failed, errCode = %{public}d", errCode);
return false;
}
DtbschedmgrDeviceInfoStorage::GetInstance().UpdateDeviceInfoStorage(dmDeviceInfoList);
HILOGI("UpdateDeviceInfoStorage success");
return true;
}
void DnetworkAdapter::RemoveDeviceChangeListener(const std::shared_ptr<DeviceListener>& listener)
{
HILOGD("RemoveDeviceChangeListener called");

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* Copyright (c) 2021-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

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Copyright (c) 2022-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

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Copyright (c) 2022-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

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* Copyright (c) 2021-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

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* Copyright (c) 2021-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
@ -15,6 +15,7 @@
#include "distributed_sched_dumper.h"
#include "accesstoken_kit.h"
#include "distributed_sched_service.h"
#include "dtbschedmgr_log.h"
#include "ipc_skeleton.h"
@ -22,9 +23,48 @@
namespace OHOS {
namespace DistributedSchedule {
namespace {
constexpr size_t MIN_ARGS_SIZE = 1;
const std::string ARGS_CONNECT_REMOTE_ABILITY = "-connect";
const std::string TAG = "DistributedSchedDumper";
const std::string HIDUMPER_PROCESS_NAME = "hidumper_service";
const std::string ARGS_HELP = "-h";
const std::string ARGS_CONNECT_REMOTE_ABILITY = "-connect";
constexpr size_t MIN_ARGS_SIZE = 1;
}
bool DistributedSchedDumper::Dump(const std::vector<std::string>& args, std::string& result)
{
result.clear();
if (!CanDump()) {
result.append("Dump failed, not allowed");
return false;
}
if (args.size() < MIN_ARGS_SIZE) {
return DumpDefault(result);
}
if (args.size() == MIN_ARGS_SIZE) {
// -h
if (args[0] == ARGS_HELP) {
ShowHelp(result);
return true;
}
// -connect
if (args[0] == ARGS_CONNECT_REMOTE_ABILITY) {
ShowConnectRemoteAbility(result);
return true;
}
}
IllegalInput(result);
return false;
}
bool DistributedSchedDumper::CanDump()
{
uint32_t accessToken = IPCSkeleton::GetCallingTokenID();
Security::AccessToken::NativeTokenInfo nativeTokenInfo;
int32_t result = Security::AccessToken::AccessTokenKit::GetNativeTokenInfo(accessToken, nativeTokenInfo);
if (result == ERR_OK && nativeTokenInfo.processName == HIDUMPER_PROCESS_NAME) {
return true;
}
return false;
}
bool DistributedSchedDumper::DumpDefault(std::string& result)
@ -35,27 +75,22 @@ bool DistributedSchedDumper::DumpDefault(std::string& result)
return true;
}
bool DistributedSchedDumper::Dump(const std::vector<std::string>& args, std::string& result)
{
result.clear();
if (args.size() < MIN_ARGS_SIZE) {
return DumpDefault(result);
}
if (args.size() == MIN_ARGS_SIZE) {
// -connect
if (args[0] == ARGS_CONNECT_REMOTE_ABILITY) {
ShowConnectRemoteAbility(result);
return true;
}
}
return false;
}
void DistributedSchedDumper::ShowConnectRemoteAbility(std::string& result)
{
DistributedSchedService::GetInstance().DumpConnectInfo(result);
}
void DistributedSchedDumper::ShowHelp(std::string& result)
{
result.append("DistributedSched Dump options:\n")
.append(" [-h] [cmd]...\n")
.append("cmd maybe one of:\n")
.append(" -connect: show all connected remote abilities.\n");
}
void DistributedSchedDumper::IllegalInput(std::string& result)
{
result.append("The arguments are illegal and you can enter '-h' for help.\n");
}
} // namespace DistributedSchedule
} // namespace OHOS

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2021-2022 Huawei Device Co., Ltd.
* Copyright (c) 2021-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
@ -22,7 +22,6 @@
#include "ability_manager_client.h"
#include "ability_manager_errors.h"
#include "adapter/dnetwork_adapter.h"
#include "app_connection_stub.h"
#include "bundle/bundle_manager_internal.h"
#include "connect_death_recipient.h"
#include "datetime_ex.h"
@ -96,55 +95,10 @@ constexpr int64_t CONTINUATION_TIMEOUT = 20000; // 20s
constexpr int64_t CHECK_REMOTE_INSTALL_ABILITY = 40000;
}
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
}
int32_t ConnectAbility(const sptr<DmsNotifier>& dmsNotifier, int32_t token,
const std::shared_ptr<ContinuationExtraParams>& continuationExtraParams)
{
return DistributedSchedService::GetInstance().ConnectAbility(dmsNotifier, token, continuationExtraParams);
}
int32_t DisconnectAbility()
{
return DistributedSchedService::GetInstance().DisconnectAbility();
}
bool DistributedSchedDump(const std::vector<std::string>& args, std::string& result)
{
return DistributedSchedDumper::Dump(args, result);
}
}
IMPLEMENT_SINGLE_INSTANCE(DistributedSchedService);
static const sptr<DistributedSchedService> INSTANCE = &DistributedSchedService::GetInstance();
const bool REGISTER_RESULT = SystemAbility::MakeAndRegisterAbility(&DistributedSchedService::GetInstance());
DistributedSchedService::DistributedSchedService()
DistributedSchedService::DistributedSchedService() : SystemAbility(DISTRIBUTED_SCHED_SA_ID, true)
{
}
@ -163,25 +117,64 @@ void DistributedSchedService::OnStart()
HILOGW("DmsCallbackTaskInitCallbackFunc timeout, taskId:%{public}" PRId64 ".", taskId);
NotifyCompleteFreeInstallFromRemote(taskId, AAFwk::FREE_INSTALL_TIMEOUT);
};
dschedContinuation_ = std::make_shared<DSchedContinuation>();
dmsCallbackTask_ = std::make_shared<DmsCallbackTask>();
dschedContinuation_->Init(continuationCallback);
dmsCallbackTask_->Init(freeCallback);
HILOGI("OnStart start service success.");
Publish(this);
}
void DistributedSchedService::OnStop()
{
HILOGD("begin");
}
int32_t DistributedSchedService::Dump(int32_t fd, const std::vector<std::u16string>& args)
{
std::vector<std::string> argsInStr8;
for (const auto& arg : args) {
argsInStr8.emplace_back(Str16ToStr8(arg));
}
std::string result;
DistributedSchedDumper::Dump(argsInStr8, result);
if (!SaveStringToFd(fd, result)) {
HILOGE("save to fd failed");
return DMS_WRITE_FILE_FAILED_ERR;
}
return ERR_OK;
}
void DistributedSchedService::DeviceOnlineNotify(const std::string& deviceId)
{
DistributedSchedAdapter::GetInstance().DeviceOnline(deviceId);
#ifdef SUPPORT_DISTRIBUTED_MISSION_MANAGER
DistributedSchedMissionManager::GetInstance().DeviceOnlineNotify(deviceId);
#endif
}
void DistributedSchedService::DeviceOfflineNotify(const std::string& deviceId)
{
DistributedSchedAdapter::GetInstance().DeviceOffline(deviceId);
#ifdef SUPPORT_DISTRIBUTED_MISSION_MANAGER
DistributedSchedMissionManager::GetInstance().DeviceOfflineNotify(deviceId);
#endif
}
bool DistributedSchedService::Init()
{
HILOGD("Init ready to init.");
HILOGD("ready to init.");
DnetworkAdapter::GetInstance()->Init();
if (!DtbschedmgrDeviceInfoStorage::GetInstance().Init()) {
HILOGW("DtbschedmgrDeviceInfoStorage init failed.");
}
#ifdef SUPPORT_DISTRIBUTED_MISSION_MANAGER
DistributedSchedMissionManager::GetInstance().Init();
#endif
HILOGD("Init init success.");
DistributedSchedAdapter::GetInstance().Init();
#ifdef SUPPORT_DISTRIBUTED_MISSION_MANAGER
DistributedSchedMissionManager::GetInstance().InitDataStorage();
#endif
DistributedSchedAdapter::GetInstance().Init();
HILOGD("init success.");
connectDeathRecipient_ = sptr<IRemoteObject::DeathRecipient>(new ConnectDeathRecipient());
callerDeathRecipient_ = sptr<IRemoteObject::DeathRecipient>(new CallerDeathRecipient());
callerDeathRecipientForLocalDevice_ = sptr<IRemoteObject::DeathRecipient>(
@ -2027,42 +2020,6 @@ int32_t DistributedSchedService::NotifyFreeInstallResult(const CallbackTaskItem
return item.callback->SendRequest(IASS_CALLBACK_ON_REMOTE_FREE_INSTALL_DONE, data, reply, option);
}
int32_t DistributedSchedService::ConnectAbility(const sptr<DmsNotifier>& dmsNotifier, int32_t token,
const std::shared_ptr<ContinuationExtraParams>& continuationExtraParams)
{
Want want;
want.SetAction(DMS_HIPLAY_ACTION);
AppExecFwk::ExtensionAbilityInfo extensionAbility;
if (!BundleManagerInternal::QueryExtensionAbilityInfo(want, extensionAbility)) {
HILOGE("QueryExtensionAbilityInfo failed");
return CONNECT_ABILITY_FAILED;
}
if (connect_ == nullptr) {
connect_ = new AppConnectionStub(dmsNotifier, token, continuationExtraParams);
}
int32_t errCode = DistributedSchedAdapter::GetInstance().ConnectAbility(want, connect_, this);
if (errCode != ERR_OK) {
HILOGE("ConnectAbility failed");
connect_ = nullptr;
return CONNECT_ABILITY_FAILED;
}
return ERR_OK;
}
int32_t DistributedSchedService::DisconnectAbility()
{
if (connect_ == nullptr) {
return ERR_NULL_OBJECT;
}
int32_t errCode = DistributedSchedAdapter::GetInstance().DisconnectAbility(connect_);
connect_ = nullptr;
if (errCode != ERR_OK) {
HILOGE("DisconnectAbility failed");
return DISCONNECT_ABILITY_FAILED;
}
return ERR_OK;
}
int32_t DistributedSchedService::CheckTargetPermission(const OHOS::AAFwk::Want& want,
const CallerInfo& callerInfo, const AccountInfo& accountInfo, int32_t flag, bool needQueryExtension)
{

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Copyright (c) 2022-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
@ -77,10 +77,8 @@ int32_t DmsVersionManager::GetRemoteDmsVersion(const std::string& deviceId, DmsV
int32_t DmsVersionManager::GetAppInfoFromDP(const std::string& deviceId, std::string& appInfoJsonData)
{
DeviceProfile::ServiceCharacteristicProfile profile;
int32_t result = IN_PROCESS_CALL(
DeviceProfile::DistributedDeviceProfileClient::GetInstance().GetDeviceProfile(deviceId,
DMS_SERVICE_ID, profile)
);
int32_t result = DeviceProfile::DistributedDeviceProfileClient::GetInstance().GetDeviceProfile(deviceId,
DMS_SERVICE_ID, profile);
if (result != ERR_OK) {
return result;
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2021-2022 Huawei Device Co., Ltd.
* Copyright (c) 2021-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
@ -19,8 +19,8 @@
#include <thread>
#include "distributed_device_node_listener.h"
#include "distributed_sched_service.h"
#include "dtbschedmgr_log.h"
#include "ipc_object_proxy.h"
#include "ipc_skeleton.h"
#include "iservice_registry.h"
@ -65,12 +65,6 @@ bool DtbschedmgrDeviceInfoStorage::Init()
return true;
}
bool DtbschedmgrDeviceInfoStorage::Init(const sptr<DmsNotifier>& listener)
{
listener_ = listener;
return Init();
}
bool DtbschedmgrDeviceInfoStorage::ConnectSoftbus()
{
ClearAllDevices();
@ -179,6 +173,21 @@ void DtbschedmgrDeviceInfoStorage::GetDeviceIdSet(std::set<std::string>& deviceI
}
}
void DtbschedmgrDeviceInfoStorage::UpdateDeviceInfoStorage(
const std::vector<DmDeviceInfo>& dmDeviceInfoList)
{
for (const auto& dmDeviceInfo : dmDeviceInfoList) {
auto deviceInfo = std::make_shared<DmsDeviceInfo>(
dmDeviceInfo.deviceName, dmDeviceInfo.deviceTypeId, dmDeviceInfo.deviceId);
std::string deviceId = deviceInfo->GetDeviceId();
RegisterUuidNetworkIdMap(deviceId);
{
lock_guard<mutex> autoLock(deviceLock_);
remoteDevices_[deviceId] = deviceInfo;
}
}
}
bool DtbschedmgrDeviceInfoStorage::GetLocalDeviceId(std::string& deviceId)
{
return GetLocalDeviceFromDnet(deviceId);
@ -279,9 +288,7 @@ void DtbschedmgrDeviceInfoStorage::DeviceOnlineNotify(const std::shared_ptr<DmsD
lock_guard<mutex> autoLock(deviceLock_);
remoteDevices_[deviceId] = devInfo;
}
if (listener_!= nullptr) {
listener_->DeviceOnlineNotify(deviceId);
}
DistributedSchedService::GetInstance().DeviceOnlineNotify(deviceId);
};
if (!networkIdMgrHandler_->PostTask(nodeOnline)) {
HILOGE("DeviceOnlineNotify handler postTask failed");
@ -304,9 +311,7 @@ void DtbschedmgrDeviceInfoStorage::DeviceOfflineNotify(const std::string& device
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);
}
DistributedSchedService::GetInstance().DeviceOfflineNotify(deviceId);
UnregisterUuidNetworkIdMap(deviceId);
lock_guard<mutex> autoLock(deviceLock_);
remoteDevices_.erase(deviceId);

View File

@ -1,4 +1,4 @@
# Copyright (c) 2021-2022 Huawei Device Co., Ltd.
# Copyright (c) 2021-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
@ -42,9 +42,11 @@ dsched_external_deps = [
"bundle_framework:appexecfwk_core",
"c_utils:utils",
"device_auth:deviceauth_sdk",
"device_info_manager:distributed_device_profile_client",
"device_manager:devicemanagersdk",
"dmsfwk:continuation_manager",
"eventhandler:libeventhandler",
"hisysevent_native:libhisysevent",
"hitrace_native:hitrace_meter",
"hitrace_native:libhitracechain",
"hiviewdfx_hilog_native:libhilog",
@ -77,7 +79,6 @@ if (efficiency_manager_service_enable) {
}
dsched_public_deps = [
"//foundation/ability/dmsfwk/services/base:dmsbaseinner",
"//third_party/googletest:gmock_main",
"//third_party/googletest:gtest_main",
"//third_party/libxml2:libxml2",
@ -86,10 +87,14 @@ 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/app_connection_stub.cpp",
"${distributed_service}/dtbschedmgr/src/adapter/dnetwork_adapter.cpp",
"${distributed_service}/dtbschedmgr/src/bundle/bundle_manager_callback_stub.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/dfx/dms_hisysevent_report.cpp",
"${distributed_service}/dtbschedmgr/src/dfx/dms_hitrace_chain.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",
@ -102,6 +107,8 @@ 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/dms_version_manager.cpp",
"${distributed_service}/dtbschedmgr/src/dtbschedmgr_device_info_storage.cpp",
"unittest/distributed_sched_util.cpp",
]
@ -232,7 +239,6 @@ ohos_unittest("dschedconnecttest") {
module_out_path = module_output_path
sources = [
"unittest/app_connection_stub_test.cpp",
"unittest/distributed_sched_connect_test.cpp",
"unittest/mock_remote_stub.cpp",
]
@ -350,6 +356,28 @@ ohos_unittest("distributeduidtest") {
subsystem_name = "ability"
}
ohos_unittest("dmsbasetest") {
module_out_path = module_output_path
sources = [
"unittest/deviceManager/dms_device_info_test.cpp",
"unittest/dfx/dms_hisysevent_report_test.cpp",
"unittest/dms_network_adapter_test.cpp",
"unittest/dtbschedmgr_device_info_storage_test.cpp",
]
sources += dtbschedmgr_sources
configs = [
":test_config",
"./resource:coverage_flags",
]
configs += dsched_configs
if (is_standard_system) {
external_deps = dsched_external_deps
public_deps = dsched_public_deps
}
part_name = "dmsfwk"
subsystem_name = "ability"
}
group("unittest") {
testonly = true
deps = [
@ -357,6 +385,7 @@ group("unittest") {
":distributedcalltest",
":distributedschedsvrtest",
":distributeduidtest",
":dmsbasetest",
":dmsfreeinstallcbtest",
":dschedconnecttest",
":dschedcontinuetest",

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Copyright (c) 2022-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

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Copyright (c) 2022-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

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* Copyright (c) 2021-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
@ -119,6 +119,9 @@ void AbilityConnectionWrapperStubTest::OnAbilityDisconnectDone(const AppExecFwk:
void DistributedSchedConnectTest::SetUpTestCase()
{
if (!DistributedSchedUtil::LoadDistributedSchedService()) {
DTEST_LOG << "DistributedSchedConnectTest::SetUpTestCase LoadDistributedSchedService failed" << std::endl;
}
const std::string pkgName = "DBinderBus_" + std::to_string(getpid());
std::shared_ptr<DmInitCallback> initCallback_ = std::make_shared<DeviceInitCallBack>();
DeviceManager::GetInstance().InitDeviceManager(pkgName, initCallback_);
@ -228,7 +231,6 @@ sptr<IDistributedSched> DistributedSchedConnectTest::GetDms()
DTEST_LOG << "distributedObject sm is nullptr" << std::endl;
return nullptr;
}
EXPECT_TRUE(distributedObject != nullptr);
return iface_cast<IDistributedSched>(distributedObject);
}
@ -248,6 +250,10 @@ HWTEST_F(DistributedSchedConnectTest, DumpConnectInfo_001, TestSize.Level1)
}
auto dms = samgr->GetSystemAbility(DISTRIBUTED_SCHED_SA_ID);
if (dms == nullptr) {
DTEST_LOG << "dms is nullptr" << std::endl;
return;
}
std::vector<std::u16string> args;
args.push_back(u"-connect");
int32_t result = dms->Dump(STDOUT_FD, args);

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* Copyright (c) 2021-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
@ -34,11 +34,13 @@ const std::u16string MOCK_DEVICE_ID = u"MOCK_DEVICE_ID";
constexpr int32_t MOCK_SESSION_ID = 123;
constexpr int32_t MOCK_TASK_ID = 456;
const string LOCAL_DEVICE_ID = "192.168.43.100";
constexpr int32_t REQUEST_CODE_ERR = 305;
}
void DSchedContinuationTest::SetUpTestCase()
{
if (!DistributedSchedUtil::LoadDistributedSchedService()) {
DTEST_LOG << "DSchedContinuationTest::SetUpTestCase LoadDistributedSchedService failed" << std::endl;
}
const std::string pkgName = "DBinderBus_" + std::to_string(getpid());
std::shared_ptr<DmInitCallback> initCallback_ = std::make_shared<DeviceInitCallBack>();
DeviceManager::GetInstance().InitDeviceManager(pkgName, initCallback_);
@ -102,12 +104,12 @@ sptr<IDistributedSched> DSchedContinuationTest::GetDms()
}
DTEST_LOG << "DSchedContinuationTest sm is not nullptr" << std::endl;
auto distributedObject = sm->GetSystemAbility(DISTRIBUTED_SCHED_SA_ID);
EXPECT_TRUE(distributedObject != nullptr);
proxy_ = iface_cast<IDistributedSched>(distributedObject);
if (proxy_ == nullptr) {
DTEST_LOG << "DSchedContinuationTest DistributedSched is nullptr" << std::endl;
} else {
DTEST_LOG << "DSchedContinuationTest DistributedSched is not nullptr" << std::endl;
}
DTEST_LOG << "DSchedContinuationTest DistributedSched is not nullptr" << std::endl;
return proxy_;
}
@ -1291,7 +1293,7 @@ HWTEST_F(DSchedContinuationTest, ProxyCallContinueMission001, TestSize.Level3)
DtbschedmgrDeviceInfoStorage::GetInstance().GetLocalDeviceId(srcDeviceId);
WantParams wantParams;
int32_t ret = proxy->ContinueMission(srcDeviceId, "MockdevId", 0, GetDSchedService(), wantParams);
EXPECT_EQ(ret, DMS_PERMISSION_DENIED);
EXPECT_EQ(ret, MISSION_FOR_CONTINUING_IS_NOT_ALIVE);
DTEST_LOG << "DistributedSchedServiceTest ProxyCallContinueMission001 end" << std::endl;
}
@ -1312,7 +1314,7 @@ HWTEST_F(DSchedContinuationTest, ProxyCallContinueMission002, TestSize.Level3)
DtbschedmgrDeviceInfoStorage::GetInstance().GetLocalDeviceId(srcDeviceId);
WantParams wantParams;
int32_t ret = proxy->ContinueMission(srcDeviceId, "MockdevId", 0, nullptr, wantParams);
EXPECT_EQ(ret, ERR_NULL_OBJECT);
EXPECT_EQ(ret, INVALID_PARAMETERS_ERR);
DTEST_LOG << "DistributedSchedServiceTest ProxyCallContinueMission002 end" << std::endl;
}
@ -1332,7 +1334,7 @@ HWTEST_F(DSchedContinuationTest, ProxyCallStartContinuation001, TestSize.Level3)
OHOS::AAFwk::Want want;
want.SetElementName("123_remote_device_id", "ohos.demo.bundleName", "abilityName");
int32_t ret = proxy->StartContinuation(want, 0, 0, 0, 0);
EXPECT_EQ(ret, DMS_PERMISSION_DENIED);
EXPECT_EQ(ret, INVALID_REMOTE_PARAMETERS_ERR);
DTEST_LOG << "DistributedSchedServiceTest ProxyCallStartContinuation001 end" << std::endl;
}
@ -1353,7 +1355,7 @@ HWTEST_F(DSchedContinuationTest, ProxyCallNotifyContinuationResultFromRemote001,
DtbschedmgrDeviceInfoStorage::GetInstance().GetLocalDeviceId(srcDeviceId);
proxy->NotifyCompleteContinuation(Str8ToStr16(srcDeviceId), 0, true);
int32_t ret = proxy->NotifyContinuationResultFromRemote(0, true);
EXPECT_EQ(ret, REQUEST_CODE_ERR);
EXPECT_EQ(ret, INVALID_REMOTE_PARAMETERS_ERR);
DTEST_LOG << "DistributedSchedServiceTest ProxyCallNotifyContinuationResultFromRemote001 end" << std::endl;
}
@ -1396,7 +1398,7 @@ HWTEST_F(DSchedContinuationTest, ProxyCallStartRemoteAbilityByCall001, TestSize.
string abilityName = "abilityName";
std::shared_ptr<Want> spWant = MockWant(bundleName, abilityName, 0);
int32_t ret = proxy->StartRemoteAbilityByCall(*spWant, nullptr, 0, 0, 1);
EXPECT_EQ(ret, ERR_NULL_OBJECT);
EXPECT_EQ(ret, INVALID_PARAMETERS_ERR);
DTEST_LOG << "DistributedSchedServiceTest ProxyCallStartRemoteAbilityByCall001 end" << std::endl;
}
@ -1437,7 +1439,7 @@ HWTEST_F(DSchedContinuationTest, ProxyCallReleaseRemoteAbility001, TestSize.Leve
AppExecFwk::ElementName element("", "com.ohos.distributedmusicplayer",
"com.ohos.distributedmusicplayer.MainAbility");
int32_t ret = proxy->ReleaseRemoteAbility(nullptr, element);
EXPECT_EQ(ret, ERR_NULL_OBJECT);
EXPECT_EQ(ret, INVALID_PARAMETERS_ERR);
DTEST_LOG << "DistributedSchedServiceTest ProxyCallReleaseRemoteAbility001 end" << std::endl;
}
@ -1489,7 +1491,7 @@ HWTEST_F(DSchedContinuationTest, ProxyCallStartAbilityByCallFromRemote001, TestS
accountInfo.groupIdList.push_back("123456");
int32_t ret = proxy->StartAbilityByCallFromRemote(*spWant, nullptr, callerInfo, accountInfo);
EXPECT_EQ(ret, ERR_NULL_OBJECT);
EXPECT_EQ(ret, INVALID_REMOTE_PARAMETERS_ERR);
DTEST_LOG << "DistributedSchedServiceTest ProxyCallReleaseRemoteAbility001 end" << std::endl;
}
@ -1547,7 +1549,7 @@ HWTEST_F(DSchedContinuationTest, ProxyCallReleaseAbilityFromRemote001, TestSize.
AppExecFwk::ElementName element("", "com.ohos.distributedmusicplayer",
"com.ohos.distributedmusicplayer.MainAbility");
int32_t ret = proxy->ReleaseAbilityFromRemote(nullptr, element, callerInfo);
EXPECT_EQ(ret, ERR_NULL_OBJECT);
EXPECT_EQ(ret, INVALID_REMOTE_PARAMETERS_ERR);
DTEST_LOG << "DistributedSchedServiceTest ProxyCallReleaseAbilityFromRemote001 end" << std::endl;
}
@ -1619,7 +1621,7 @@ HWTEST_F(DSchedContinuationTest, ProxyCallStartRemoteFreeInstall002, TestSize.Le
std::shared_ptr<Want> spWant = MockWant(bundleName, abilityName, 0);
int32_t ret = proxy->StartRemoteFreeInstall(*spWant, 0, 1, 1, nullptr);
EXPECT_EQ(ret, ERR_NULL_OBJECT);
EXPECT_EQ(ret, INVALID_PARAMETERS_ERR);
DTEST_LOG << "DistributedSchedServiceTest ProxyCallStartRemoteFreeInstall002 end" << std::endl;
}
@ -1676,7 +1678,7 @@ HWTEST_F(DSchedContinuationTest, ProxyCallStartShareFormFromRemote001, TestSize.
}
const OHOS::AppExecFwk::FormShareInfo formShareInfo {};
int32_t ret = proxy->StartShareFormFromRemote("", formShareInfo);
EXPECT_EQ(ret, INVALID_PARAMETERS_ERR);
EXPECT_EQ(ret, ERR_OK);
DTEST_LOG << "DistributedSchedServiceTest ProxyCallStartShareFormFromRemote001 end" << std::endl;
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Copyright (c) 2022-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
@ -68,7 +68,7 @@ HWTEST_F(DistributedSchedDumperTest, Dump_001, TestSize.Level3)
const std::vector<std::string> args = {};
std::string result = "";
bool res = DistributedSchedDumper::Dump(args, result);
EXPECT_EQ(res, true);
EXPECT_EQ(res, false);
DTEST_LOG << "DistributedSchedDumperTest Dump_001 end" << std::endl;
}
@ -84,7 +84,7 @@ HWTEST_F(DistributedSchedDumperTest, Dump_002, TestSize.Level3)
const std::vector<std::string> args = {"-connect"};
std::string result = "";
bool res = DistributedSchedDumper::Dump(args, result);
EXPECT_EQ(res, true);
EXPECT_EQ(res, false);
DTEST_LOG << "DistributedSchedDumperTest Dump_002 end" << std::endl;
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2021-2022 Huawei Device Co., Ltd.
* Copyright (c) 2021-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
@ -87,6 +87,9 @@ protected:
void DistributedSchedServiceTest::SetUpTestCase()
{
if (!DistributedSchedUtil::LoadDistributedSchedService()) {
DTEST_LOG << "DistributedSchedServiceTest::SetUpTestCase LoadDistributedSchedService failed" << std::endl;
}
const std::string pkgName = "DBinderBus_" + std::to_string(getpid());
std::shared_ptr<DmInitCallback> initCallback_ = std::make_shared<DeviceInitCallBack>();
DeviceManager::GetInstance().InitDeviceManager(pkgName, initCallback_);
@ -119,12 +122,12 @@ sptr<IDistributedSched> DistributedSchedServiceTest::GetDms()
}
DTEST_LOG << "DistributedSchedServiceTest sm is not nullptr" << std::endl;
auto distributedObject = sm->GetSystemAbility(DISTRIBUTED_SCHED_SA_ID);
EXPECT_TRUE(distributedObject != nullptr);
proxy_ = iface_cast<IDistributedSched>(distributedObject);
if (proxy_ == nullptr) {
DTEST_LOG << "DistributedSchedServiceTest DistributedSched is nullptr" << std::endl;
} else {
DTEST_LOG << "DistributedSchedServiceTest DistributedSched is not nullptr" << std::endl;
}
DTEST_LOG << "DistributedSchedServiceTest DistributedSched is not nullptr" << std::endl;
return proxy_;
}
@ -1214,9 +1217,9 @@ HWTEST_F(DistributedSchedServiceTest, StartAbilityByCallFromRemote_001, TestSize
EXPECT_EQ(result, true);
IDistributedSched::AccountInfo accountInfo;
accountInfo.accountType = IDistributedSched::SAME_ACCOUNT_TYPE;
int ret = DistributedSchedService::GetInstance().StartAbilityByCallFromRemote(want, connect,
callerInfo, accountInfo);
EXPECT_NE(ret, ERR_OK);
auto mockDms = iface_cast<IDistributedSched>(GetDSchedService());
int ret = mockDms->StartAbilityByCallFromRemote(want, connect, callerInfo, accountInfo);
EXPECT_EQ(ret, ERR_OK);
DTEST_LOG << "DistributedSchedServiceTest StartAbilityByCallFromRemote_001 end" << std::endl;
}
@ -1274,8 +1277,8 @@ HWTEST_F(DistributedSchedServiceTest, ConnectAbilityFromRemote_001, TestSize.Lev
EXPECT_TRUE(result);
IDistributedSched::AccountInfo accountInfo;
accountInfo.accountType = IDistributedSched::SAME_ACCOUNT_TYPE;
int ret = DistributedSchedService::GetInstance().ConnectAbilityFromRemote(want,
abilityInfo, connect, callerInfo, accountInfo);
auto mockDms = iface_cast<IDistributedSched>(GetDSchedService());
int ret = mockDms->ConnectAbilityFromRemote(want, abilityInfo, connect, callerInfo, accountInfo);
EXPECT_EQ(ret, ERR_OK);
DTEST_LOG << "DistributedSchedServiceTest ConnectAbilityFromRemote_001 end" << std::endl;
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Copyright (c) 2022-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
@ -16,14 +16,25 @@
#include "distributed_sched_util.h"
#include "accesstoken_kit.h"
#include "dtbschedmgr_log.h"
#include "if_system_ability_manager.h"
#include "iservice_registry.h"
#include "nativetoken_kit.h"
#include "system_ability_definition.h"
#include "token_setproc.h"
namespace OHOS {
namespace DistributedSchedule {
namespace {
const std::string TAG = "DistributedSchedUtil";
const char* DISTSCHED_PROCESS_NAME = "distributedsched";
constexpr int32_t DMS_LOAD_SA_TIMEOUT_MS = 10000;
}
sptr<IRemoteObject> DistributedSchedUtil::remote_ = nullptr;
std::mutex DistributedSchedUtil::remoteMutex_;
std::condition_variable DistributedSchedUtil::remoteConVar_;
void DistributedSchedUtil::MockPermission()
{
static const char *PERMS[] = {
@ -54,5 +65,58 @@ void DistributedSchedUtil::MockProcessAndPermission(const char* processName, con
SetSelfTokenID(tokenId);
OHOS::Security::AccessToken::AccessTokenKit::ReloadNativeTokenInfo();
}
bool DistributedSchedUtil::LoadDistributedSchedService()
{
std::unique_lock<std::mutex> lock(remoteMutex_);
sptr<DistributedSchedLoadCallback> loadCallback = new DistributedSchedLoadCallback();
if (loadCallback == nullptr) {
HILOGE("loadCallback is nullptr");
return false;
}
auto samgrProxy = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
if (samgrProxy == nullptr) {
HILOGE("get samgr failed");
return false;
}
int32_t ret = samgrProxy->LoadSystemAbility(DISTRIBUTED_SCHED_SA_ID, loadCallback);
if (ret != ERR_OK) {
HILOGE("load dms SA failed");
return false;
}
auto waitStatus = remoteConVar_.wait_for(lock, std::chrono::milliseconds(DMS_LOAD_SA_TIMEOUT_MS),
[]() { return remote_ != nullptr; });
if (!waitStatus) {
HILOGE("dms SA load timeout");
return false;
}
return true;
}
void DistributedSchedUtil::LoadSystemAbilitySuccessNotify(const sptr<IRemoteObject>& remoteObject)
{
std::lock_guard<std::mutex> lock(remoteMutex_);
remote_ = remoteObject;
remoteConVar_.notify_one();
}
void DistributedSchedUtil::LoadSystemAbilityFailNotify()
{
std::lock_guard<std::mutex> lock(remoteMutex_);
remote_ = nullptr;
}
void DistributedSchedLoadCallback::OnLoadSystemAbilitySuccess(
int32_t systemAbilityId, const sptr<IRemoteObject> &remoteObject)
{
HILOGD("called.");
DistributedSchedUtil::LoadSystemAbilitySuccessNotify(remoteObject);
}
void DistributedSchedLoadCallback::OnLoadSystemAbilityFail(int32_t systemAbilityId)
{
HILOGD("called.");
DistributedSchedUtil::LoadSystemAbilityFailNotify();
}
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Copyright (c) 2022-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
@ -17,6 +17,10 @@
#define DISTRIBUTED_SCHED_UTIL_H
#include <cstdint>
#include <mutex>
#include "iremote_object.h"
#include "system_ability_load_callback_stub.h"
namespace OHOS {
namespace DistributedSchedule {
@ -26,6 +30,23 @@ public:
static void MockProcess(const char* processName);
static void MockProcessAndPermission(const char* processName,
const char *perms[] = nullptr, int32_t permsNum = 0);
static bool LoadDistributedSchedService();
static void LoadSystemAbilitySuccessNotify(const sptr<IRemoteObject>& remoteObject);
static void LoadSystemAbilityFailNotify();
static std::mutex remoteMutex_;
static sptr<IRemoteObject> remote_;
static std::condition_variable remoteConVar_;
};
class DistributedSchedLoadCallback : public SystemAbilityLoadCallbackStub {
public:
DistributedSchedLoadCallback() = default;
~DistributedSchedLoadCallback() = default;
void OnLoadSystemAbilitySuccess(int32_t systemAbilityId,
const sptr<IRemoteObject> &remoteObject) override;
void OnLoadSystemAbilityFail(int32_t systemAbilityId) override;
};
} // namespace DistributedSchedule
} // namespace OHOS

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Copyright (c) 2022-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

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Copyright (c) 2022-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

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* Copyright (c) 2021-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
@ -373,5 +373,16 @@ HWTEST_F(DMSNetworkAdapterTest, RemoveDeviceChangeListener_002, TestSize.Level3)
*/
DnetworkAdapter::GetInstance()->initCallback_->OnRemoteDied();
}
/**
* @tc.name: UpdateDeviceInfoStorage_001
* @tc.desc: test UpdateDeviceInfoStorage
* @tc.type: FUNC
*/
HWTEST_F(DMSNetworkAdapterTest, UpdateDeviceInfoStorage_001, TestSize.Level3)
{
bool result = DnetworkAdapter::GetInstance()->UpdateDeviceInfoStorage();
EXPECT_EQ(result, true);
}
} // namespace DistributedSchedule
} // namespace OHOS

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Copyright (c) 2022-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
@ -15,6 +15,7 @@
#include "dtbschedmgr_device_info_storage_test.h"
#include "distributed_sched_util.h"
#include "dtbschedmgr_log.h"
#include "test_log.h"
#include <cstddef>
@ -28,77 +29,35 @@ namespace {
constexpr int32_t MAX_WAIT_TIME = 10000;
}
class MockDmsNotifier : public DmsNotifier {
public:
MockDmsNotifier() = default;
~MockDmsNotifier() = default;
void DeviceOnlineNotify(const std::string& deviceId) override;
void DeviceOfflineNotify(const std::string& deviceId) override;
void ProcessNotifierDied(const sptr<IRemoteObject>& notifier) override;
void ScheduleStartDeviceManager(const sptr<IRemoteObject>& appProxy, int32_t token,
const std::shared_ptr<ContinuationExtraParams>& continuationExtraParams = nullptr) override;
int32_t OnDeviceConnect(int32_t token, const std::vector<ContinuationResult>& continuationResults) override;
int32_t OnDeviceDisconnect(int32_t token, const std::vector<ContinuationResult>& continuationResults) override;
int32_t OnDeviceCancel() override;
};
void MockDmsNotifier::DeviceOnlineNotify(const std::string& deviceId)
{
}
void MockDmsNotifier::DeviceOfflineNotify(const std::string& deviceId)
{
}
void MockDmsNotifier::ProcessNotifierDied(const sptr<IRemoteObject>& notifier)
{
}
void MockDmsNotifier::ScheduleStartDeviceManager(const sptr<IRemoteObject>& appProxy, int32_t token,
const std::shared_ptr<ContinuationExtraParams>& continuationExtraParams)
{
}
int32_t MockDmsNotifier::OnDeviceConnect(int32_t token, const std::vector<ContinuationResult>& continuationResults)
{
return 0;
}
int32_t MockDmsNotifier::OnDeviceDisconnect(int32_t token, const std::vector<ContinuationResult>& continuationResults)
{
return 0;
}
int32_t MockDmsNotifier::OnDeviceCancel()
{
return 0;
}
int32_t DtbschedmgrDeviceInfoStorageTest::startTaskNum_ = 2;
std::mutex DtbschedmgrDeviceInfoStorageTest::caseDoneLock_;
std::condition_variable DtbschedmgrDeviceInfoStorageTest::caseDoneCondition_;
void DtbschedmgrDeviceInfoStorageTest::SetUpTestCase()
{
DTEST_LOG << "DtbschedmgrDeviceInfoStorageTest::SetUpTestCase" << std::endl;
if (!DistributedSchedUtil::LoadDistributedSchedService()) {
DTEST_LOG << "DtbschedmgrDeviceInfoStorageTest::SetUpTestCase load dms SA failed" << std::endl;
}
}
bool DtbschedmgrDeviceInfoStorageTest::isCaseDone_ = false;
std::mutex DtbschedmgrDeviceInfoStorageTest::caseDoneLock_;
std::condition_variable DtbschedmgrDeviceInfoStorageTest::caseDoneCondition_;
void DtbschedmgrDeviceInfoStorageTest::TearDownTestCase()
{
// Wait until all asyn tasks are completed before exiting the test suite
// Wait until all async tasks are completed before exiting the test suite
auto caseDoneNotifyTask = []() {
std::lock_guard<std::mutex> autoLock(caseDoneLock_);
isCaseDone_ = true;
--startTaskNum_;
caseDoneCondition_.notify_all();
};
if (DtbschedmgrDeviceInfoStorage::GetInstance().networkIdMgrHandler_ != nullptr) {
DtbschedmgrDeviceInfoStorage::GetInstance().networkIdMgrHandler_->PostTask(caseDoneNotifyTask);
}
if (DtbschedmgrDeviceInfoStorage::GetInstance().initHandler_ != nullptr) {
DtbschedmgrDeviceInfoStorage::GetInstance().initHandler_->PostTask(caseDoneNotifyTask);
}
std::unique_lock<std::mutex> lock(caseDoneLock_);
caseDoneCondition_.wait_for(lock, std::chrono::milliseconds(MAX_WAIT_TIME),
[&] () { return isCaseDone_; });
[&] () { return startTaskNum_ == 0; });
DTEST_LOG << "DtbschedmgrDeviceInfoStorageTest::TearDownTestCase" << std::endl;
}
@ -123,9 +82,8 @@ HWTEST_F(DtbschedmgrDeviceInfoStorageTest, InitTest_001, TestSize.Level3)
/**
* @tc.steps: step1. test Init with listener when initHandler_ is nullptr;
*/
sptr<DmsNotifier> listener = nullptr;
DtbschedmgrDeviceInfoStorage::GetInstance().initHandler_ = nullptr;
bool result = DtbschedmgrDeviceInfoStorage::GetInstance().Init(listener);
bool result = DtbschedmgrDeviceInfoStorage::GetInstance().Init();
EXPECT_TRUE(result);
/**
* @tc.steps: step2. test Init when initHandler_ is not nullptr;
@ -169,9 +127,6 @@ HWTEST_F(DtbschedmgrDeviceInfoStorageTest, InitNetworkIdManagerTest_001, TestSiz
/**
* @tc.steps: step2. test InitNetworkIdManager when networkIdMgrHandler_ is not nullptr;
*/
auto runner = AppExecFwk::EventRunner::Create("DmsNetworkIdManager");
DtbschedmgrDeviceInfoStorage::GetInstance().networkIdMgrHandler_ =
std::make_shared<AppExecFwk::EventHandler>(runner);
result = DtbschedmgrDeviceInfoStorage::GetInstance().InitNetworkIdManager(dnetworkAdapter);
EXPECT_TRUE(result);
/**
@ -267,19 +222,6 @@ HWTEST_F(DtbschedmgrDeviceInfoStorageTest, GetLocalDeviceFromDnetTest_001, TestS
devInfo = make_shared<DmsDeviceInfo>(deviceName, deviceType, deviceId);
DtbschedmgrDeviceInfoStorage::GetInstance().networkIdMgrHandler_ = nullptr;
DtbschedmgrDeviceInfoStorage::GetInstance().DeviceOnlineNotify(devInfo);
/**
* @tc.steps: step4. test DeviceOnlineNotify when listener_ is nullptr;
*/
auto runner = AppExecFwk::EventRunner::Create("DmsNetworkIdManager");
DtbschedmgrDeviceInfoStorage::GetInstance().networkIdMgrHandler_ =
std::make_shared<AppExecFwk::EventHandler>(runner);
DtbschedmgrDeviceInfoStorage::GetInstance().listener_ = nullptr;
DtbschedmgrDeviceInfoStorage::GetInstance().DeviceOnlineNotify(devInfo);
/**
* @tc.steps: step5. test DeviceOnlineNotify when listener_ is not nullptr;
*/
DtbschedmgrDeviceInfoStorage::GetInstance().listener_ = new MockDmsNotifier();
DtbschedmgrDeviceInfoStorage::GetInstance().DeviceOnlineNotify(devInfo);
DTEST_LOG << "DtbschedmgrDeviceInfoStorageTest GetLocalDeviceFromDnetTest_001 end" << std::endl;
}
@ -310,19 +252,6 @@ HWTEST_F(DtbschedmgrDeviceInfoStorageTest, ClearAllDevicesTest_001, TestSize.Lev
deviceId = "invalid deviceId for DeviceOnlineNotify";
DtbschedmgrDeviceInfoStorage::GetInstance().networkIdMgrHandler_ = nullptr;
DtbschedmgrDeviceInfoStorage::GetInstance().DeviceOfflineNotify(deviceId);
/**
* @tc.steps: step4. test DeviceOfflineNotify when listener_ is nullptr;
*/
auto runner = AppExecFwk::EventRunner::Create("DmsNetworkIdManager");
DtbschedmgrDeviceInfoStorage::GetInstance().networkIdMgrHandler_ =
std::make_shared<AppExecFwk::EventHandler>(runner);
DtbschedmgrDeviceInfoStorage::GetInstance().listener_ = nullptr;
DtbschedmgrDeviceInfoStorage::GetInstance().DeviceOfflineNotify(deviceId);
/**
* @tc.steps: step5. test DeviceOfflineNotify when listener_ is not nullptr;
*/
DtbschedmgrDeviceInfoStorage::GetInstance().listener_ = new MockDmsNotifier();
DtbschedmgrDeviceInfoStorage::GetInstance().DeviceOfflineNotify(deviceId);
DTEST_LOG << "DtbschedmgrDeviceInfoStorageTest ClearAllDevicesTest_001 end" << std::endl;
}
@ -438,5 +367,35 @@ HWTEST_F(DtbschedmgrDeviceInfoStorageTest, GetNetworkIdByUuidTest_001, TestSize.
DTEST_LOG << "DtbschedmgrDeviceInfoStorageTest GetNetworkIdByUuidTest_001 end" << std::endl;
}
/**
* @tc.name: UpdateDeviceInfoStorageTest_001
* @tc.desc: test UpdateDeviceInfoStorage
* @tc.type: FUNC
*/
HWTEST_F(DtbschedmgrDeviceInfoStorageTest, UpdateDeviceInfoStorageTest_001, TestSize.Level3)
{
DTEST_LOG << "DtbschedmgrDeviceInfoStorageTest UpdateDeviceInfoStorageTest_001 start" << std::endl;
std::vector<DistributedHardware::DmDeviceInfo> dmDeviceInfoList;
dmDeviceInfoList.clear();
DtbschedmgrDeviceInfoStorage::GetInstance().UpdateDeviceInfoStorage(dmDeviceInfoList);
EXPECT_EQ(dmDeviceInfoList.empty(), true);
DTEST_LOG << "DtbschedmgrDeviceInfoStorageTest UpdateDeviceInfoStorageTest_001 end" << std::endl;
}
/**
* @tc.name: UpdateDeviceInfoStorageTest_002
* @tc.desc: test UpdateDeviceInfoStorage
* @tc.type: FUNC
*/
HWTEST_F(DtbschedmgrDeviceInfoStorageTest, UpdateDeviceInfoStorageTest_002, TestSize.Level3)
{
DTEST_LOG << "DtbschedmgrDeviceInfoStorageTest UpdateDeviceInfoStorageTest_002 start" << std::endl;
std::vector<DistributedHardware::DmDeviceInfo> dmDeviceInfoList;
DistributedHardware::DmDeviceInfo dmDeviceInfo;
dmDeviceInfoList.emplace_back(dmDeviceInfo);
DtbschedmgrDeviceInfoStorage::GetInstance().UpdateDeviceInfoStorage(dmDeviceInfoList);
EXPECT_EQ(!dmDeviceInfoList.empty(), true);
DTEST_LOG << "DtbschedmgrDeviceInfoStorageTest UpdateDeviceInfoStorageTest_002 end" << std::endl;
}
} // namespace DistributedSchedule
} // namespace OHOS

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Copyright (c) 2022-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
@ -32,7 +32,7 @@ public:
static void TearDownTestCase();
void SetUp();
void TearDown();
static bool isCaseDone_;
static int32_t startTaskNum_;
static std::mutex caseDoneLock_;
static std::condition_variable caseDoneCondition_;
};

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2021-2022 Huawei Device Co., Ltd.
* Copyright (c) 2021-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
@ -60,6 +60,9 @@ std::condition_variable DMSMissionManagerTest::caseDoneCondition_;
void DMSMissionManagerTest::SetUpTestCase()
{
if (!DistributedSchedUtil::LoadDistributedSchedService()) {
DTEST_LOG << "DMSMissionManagerTest::SetUpTestCase LoadDistributedSchedService failed" << std::endl;
}
const std::string pkgName = "DBinderBus_" + std::to_string(getpid());
std::shared_ptr<DmInitCallback> initCallback_ = std::make_shared<DeviceInitCallBack>();
DeviceManager::GetInstance().InitDeviceManager(pkgName, initCallback_);
@ -102,12 +105,12 @@ sptr<IDistributedSched> DMSMissionManagerTest::GetDms()
}
DTEST_LOG << "DMSMissionManagerTest sm is not nullptr" << std::endl;
auto distributedObject = sm->GetSystemAbility(DISTRIBUTED_SCHED_SA_ID);
EXPECT_TRUE(distributedObject != nullptr);
proxy_ = iface_cast<IDistributedSched>(distributedObject);
if (proxy_ == nullptr) {
DTEST_LOG << "DMSMissionManagerTest DistributedSched is nullptr" << std::endl;
} else {
DTEST_LOG << "DMSMissionManagerTest DistributedSched is not nullptr" << std::endl;
}
DTEST_LOG << "DMSMissionManagerTest DistributedSched is not nullptr" << std::endl;
return proxy_;
}

View File

@ -1,4 +1,4 @@
# Copyright (c) 2022 Huawei Device Co., Ltd.
# Copyright (c) 2022-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
@ -27,6 +27,7 @@ config("continuationmanager_fuzz_config") {
}
dtbabilitymgr_sources = [
"${distributed_service}/dtbabilitymgr/src/continuation_manager/app_connection_stub.cpp",
"${distributed_service}/dtbabilitymgr/src/continuation_manager/app_device_callback_stub.cpp",
"${distributed_service}/dtbabilitymgr/src/continuation_manager/connect_status_info.cpp",
"${distributed_service}/dtbabilitymgr/src/continuation_manager/continuation_extra_params.cpp",
@ -41,15 +42,20 @@ dtbabilitymgr_sources = [
]
dtbabilitymgr_external_deps = [
"ability_base:want",
"ability_runtime:ability_manager",
"access_token:libaccesstoken_sdk",
"access_token:libnativetoken",
"access_token:libtoken_setproc",
"bundle_framework:appexecfwk_base",
"bundle_framework:appexecfwk_core",
"c_utils:utils",
"device_manager:devicemanagersdk",
"eventhandler:libeventhandler",
"hiviewdfx_hilog_native:libhilog",
"init:libbegetutil",
"ipc:ipc_core",
"os_account:os_account_innerkits",
"safwk:system_ability_fwk",
"samgr:samgr_proxy",
]
@ -80,8 +86,6 @@ ohos_fuzztest("ContinuationManagerFuzzTest") {
sources += dtbabilitymgr_sources
deps = [ "//foundation/ability/dmsfwk/services/base:dmsbaseinner" ]
external_deps = dtbabilitymgr_external_deps
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Copyright (c) 2022-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
@ -18,21 +18,17 @@
#include <cstddef>
#include <cstdint>
#include "dtbschedmgr_log.h"
#include "distributed_ability_manager_interface.h"
#include "distributed_ability_manager_stub.h"
#include "distributed_ability_manager_service.h"
#include "base/continuationmgr_log.h"
#include "fuzz_util.h"
namespace OHOS {
namespace DistributedSchedule {
namespace {
constexpr int32_t DISTRIBUTED_SCHED_SA_ID = 1401;
constexpr int32_t CONTINUATION_MANAGER_SA_ID = 1404;
constexpr size_t THRESHOLD = 10;
constexpr uint16_t MAX_CALL_TRANSACTION = 510;
constexpr int32_t OFFSET = 4;
const std::u16string DMS_INTERFACE_TOKEN = u"OHOS.DistributedSchedule.IDistributedAbilityManager";
const std::u16string DMS_STUB_INTERFACE_TOKEN = u"ohos.distributedschedule.accessToken";
const std::string TAG = "ContinuationFuzz";
}
@ -51,7 +47,7 @@ void FuzzUnregister(const uint8_t* rawData, size_t size)
rawData = rawData + OFFSET;
size = size - OFFSET;
MessageParcel data;
data.WriteInterfaceToken(DMS_STUB_INTERFACE_TOKEN);
data.WriteInterfaceToken(DMS_INTERFACE_TOKEN);
data.WriteBuffer(rawData, size);
data.RewindRead(0);
MessageParcel reply;
@ -61,7 +57,7 @@ void FuzzUnregister(const uint8_t* rawData, size_t size)
HILOGE("system ability manager is nullptr.");
return;
}
auto remoteObj = systemAbilityMgr->GetSystemAbility(DISTRIBUTED_SCHED_SA_ID);
auto remoteObj = systemAbilityMgr->GetSystemAbility(CONTINUATION_MANAGER_SA_ID);
if (remoteObj == nullptr) {
HILOGE("failed to get form manager service");
return;