diff --git a/etc/init/BUILD.gn b/etc/init/BUILD.gn new file mode 100644 index 00000000..e34a927e --- /dev/null +++ b/etc/init/BUILD.gn @@ -0,0 +1,29 @@ + +# Copyright (c) 2021 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//build/ohos.gni") + +################################################################################# + + +group("etc") { + deps = [ ":distributedsched.rc" ] +} + +ohos_prebuilt_etc("distributedsched.rc") { + source = "distributedsched.rc" + relative_install_dir = "init" + subsystem_name = "distributedschedule" + part_name = "dmsfwk_standard" +} diff --git a/etc/init/distributedsched.rc b/etc/init/distributedsched.rc new file mode 100644 index 00000000..a4be889e --- /dev/null +++ b/etc/init/distributedsched.rc @@ -0,0 +1,21 @@ +# Copyright (c) 2021 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +on post-fs-data + start distributedsched + +service distributedsched /system/bin/sa_main /system/profile/distributedsched.xml + class z_core + user system + group system shell + seclabel u:r:distributedsched:s0 \ No newline at end of file diff --git a/interfaces/innerkits/uri/BUILD.gn b/interfaces/innerkits/uri/BUILD.gn index c9cb9e62..7a5ffe58 100755 --- a/interfaces/innerkits/uri/BUILD.gn +++ b/interfaces/innerkits/uri/BUILD.gn @@ -33,7 +33,7 @@ ohos_shared_library("zuri") { "hiviewdfx_hilog_native:libhilog", "ipc:ipc_core", ] - part_name = "dmsfwk_L2" + part_name = "dmsfwk_standard" } deps = [ "//utils/native/base:utils" ] subsystem_name = "distributedschedule" diff --git a/ohos.build b/ohos.build index 4169c3f7..5a29b1e2 100755 --- a/ohos.build +++ b/ohos.build @@ -1,6 +1,6 @@ { "parts": { - "dmsfwk_L2": { + "dmsfwk_standard": { "variants": ["phone", "wearable"], "inner_kits": [ { @@ -14,6 +14,9 @@ } ], "module_list": [ + "//foundation/distributedschedule/dmsfwk/etc/init:etc", + "//foundation/distributedschedule/dmsfwk/sa_profile:dms_sa_profile", + "//foundation/distributedschedule/dmsfwk/services/dtbschedmgr:distributedschedsvr" ], "system_kits": [], "test_list": [] diff --git a/sa_profile/1401.xml b/sa_profile/1401.xml new file mode 100644 index 00000000..b0b67be0 --- /dev/null +++ b/sa_profile/1401.xml @@ -0,0 +1,26 @@ + + + + distributedsched + + 1401 + libdistributedschedsvr.z.so + + + true + true + 1 + + \ No newline at end of file diff --git a/sa_profile/BUILD.gn b/sa_profile/BUILD.gn new file mode 100644 index 00000000..a750434a --- /dev/null +++ b/sa_profile/BUILD.gn @@ -0,0 +1,19 @@ +# Copyright (c) 2021 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//build/ohos/sa_profile/sa_profile.gni") + +ohos_sa_profile("dms_sa_profile") { + sources = [ "1401.xml" ] + part_name = "dmsfwk_standard" +} diff --git a/services/dtbschedmgr/BUILD.gn b/services/dtbschedmgr/BUILD.gn new file mode 100644 index 00000000..d3165e89 --- /dev/null +++ b/services/dtbschedmgr/BUILD.gn @@ -0,0 +1,57 @@ +# Copyright (c) 2021 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + + +import("//build/ohos.gni") +import("//build/ohos_var.gni") + +config("distributed_sched_config") { + visibility = [ ":*" ] + include_dirs = [ + "include", + ] + + cflags_cc = [ "-fexceptions" ] + } + +ohos_shared_library("distributedschedsvr") { + install_enable = true + sources = [ + "src/distributed_sched_proxy.cpp", + "src/distributed_sched_service.cpp", + "src/distributed_sched_stub.cpp", + ] + + configs = [ ":distributed_sched_config" ] + + deps = [ + "//base/hiviewdfx/hilog/interfaces/native/innerkits:libhilog", + "//foundation/aafwk/standard/interfaces/innerkits/ability_manager:ability_manager", + "//foundation/aafwk/standard/interfaces/innerkits/base:base", + "//foundation/aafwk/standard/interfaces/innerkits/want:want", + "//foundation/appexecfwk/standard/common:libappexecfwk_common", + "//foundation/appexecfwk/standard/interfaces/innerkits/appexecfwk_base:appexecfwk_base", + "//foundation/appexecfwk/standard/interfaces/innerkits/libeventhandler:libeventhandler", + "//foundation/distributedschedule/safwk/interfaces/innerkits/safwk:system_ability_fwk", + "//foundation/distributedschedule/samgr/interfaces/innerkits/samgr_proxy:samgr_proxy", + "//utils/native/base:utils", + ] + + external_deps = [ + "hiviewdfx_hilog_native:libhilog", + "ipc:ipc_core", + ] + + part_name = "dmsfwk_standard" + subsystem_name = "distributedschedule" +} diff --git a/services/dtbschedmgr/include/distributed_sched_interface.h b/services/dtbschedmgr/include/distributed_sched_interface.h new file mode 100644 index 00000000..0f76b4ba --- /dev/null +++ b/services/dtbschedmgr/include/distributed_sched_interface.h @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef HARMONYOS_DISTRIBUTED_SCHED_INTERFACE_H +#define HARMONYOS_DISTRIBUTED_SCHED_INTERFACE_H + +#include "iremote_broker.h" +#include "ohos/aafwk/content/want.h" + +namespace OHOS { +namespace DistributedSchedule { +class IDistributedSched : public OHOS::IRemoteBroker{ +public: + DECLARE_INTERFACE_DESCRIPTOR(u"OHOS.DistributedSchedule.IDistributedSched"); + virtual int32_t StartRemoteAbility(const OHOS::AAFwk::Want& userWant, OHOS::AAFwk::Want& innerWant, + int32_t requestCode) = 0; + virtual int32_t StartAbilityFromRemote(const OHOS::AAFwk::Want& userWant, OHOS::AAFwk::Want& innerWant, + int32_t requestCode) = 0; + enum{ + START_REMOTE_ABILITY = 1, + STOP_REMOTE_ABILITY = 3, + START_ABILITY_FROM_REMOTE = 4, + STOP_ABILITY_FROM_REMOTE = 5, + CONNECT_REMOTE_ABILITY = 6, + DISCONNECT_REMOTE_ABILITY = 7, + CONNECT_ABILITY_FROM_REMOTE = 8, + DISCONNECT_ABILITY_FROM_REMOTE = 9, + START_CONTINUATION = 11, + NOTIFY_COMPLETE_CONTINUATION = 12, + NOTIFY_CONTINUATION_RESULT_FROM_REMOTE = 13, + REGISTER_ABILITY_TOKEN = 14, + UNREGISTER_ABILITY_TOKEN = 15, + CONTINUE_ABILITY = 16, + NOTIFY_PROCESS_DIED_FROM_REMOTE = 17, + GET_REMOTE_APPTHREAD = 35, + }; +}; + +} // namespace DistributedSchedule +} // namespace OHOS + +#endif // HARMONYOS_DISTRIBUTED_SCHED_INTERFACE_H diff --git a/services/dtbschedmgr/include/distributed_sched_proxy.h b/services/dtbschedmgr/include/distributed_sched_proxy.h new file mode 100644 index 00000000..ccb44eab --- /dev/null +++ b/services/dtbschedmgr/include/distributed_sched_proxy.h @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef HARMONYOS_DISTRIBUTED_SCHED_PROXY_H +#define HARMONYOS_DISTRIBUTED_SCHED_PROXY_H + +#include "distributed_sched_interface.h" +#include "iremote_proxy.h" + +namespace OHOS { +namespace DistributedSchedule { +class DistributedSchedProxy : public IRemoteProxy{ +public: + explicit DistributedSchedProxy(const sptr& impl) + : IRemoteProxy(impl) {} + ~DistributedSchedProxy(){} + int32_t StartRemoteAbility(const OHOS::AAFwk::Want& userWant, OHOS::AAFwk::Want& innerWant, int32_t requestCode) override; + int32_t StartAbilityFromRemote(const OHOS::AAFwk::Want& userWant, OHOS::AAFwk::Want& innerWant, int32_t requestCode) override; + +private: + static inline BrokerDelegator delegator_; +}; + +} // namespace DistributedSchedule +} // namespace OHOS + +#endif // HARMONYOS_DISTRIBUTED_SCHED_PROXY_H diff --git a/services/dtbschedmgr/include/distributed_sched_service.h b/services/dtbschedmgr/include/distributed_sched_service.h new file mode 100644 index 00000000..1dbddb89 --- /dev/null +++ b/services/dtbschedmgr/include/distributed_sched_service.h @@ -0,0 +1,64 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef HARMONYOS_DISTRIBUTED_SCHED_SERVICE_H +#define HARMONYOS_DISTRIBUTED_SCHED_SERVICE_H + +#include +#include +#include +#include + +#include "ability_connect_callback_interface.h" +#include "system_ability.h" +#include "distributed_sched_stub.h" +#include "iremote_object.h" +#include "iremote_proxy.h" +#include "nocopyable.h" +#include "single_instance.h" + +namespace OHOS { +namespace DistributedSchedule { +enum class ServiceRunningState { + STATE_NO_START, + STATE_RUNNING +}; +enum class TargetComponent { + HARMONY_COMPONENT, + AOSP_COMPONENT, +}; + +class DistributedSchedService : public SystemAbility, public DistributedSchedStub { +DECLARE_SYSTEM_ABILITY(DistributedSchedService); + +DECLARE_SINGLE_INSTANCE_BASE(DistributedSchedService); + +public: + ~DistributedSchedService() = default; + void OnStart() override; + void OnStop() override; + int32_t StartRemoteAbility(const OHOS::AAFwk::Want& userWant, OHOS::AAFwk::Want& innerWant, int32_t requestCode) override; + int32_t StartAbilityFromRemote(const OHOS::AAFwk::Want& userWant, OHOS::AAFwk::Want& innerWant, int32_t requestCode) override; +private: + DistributedSchedService(); + bool Init(); + sptr GetRemoteDms(const std::string& remoteDeviceId); + + bool registerToService_ = false; +}; +} // namespace DistributedSchedule +} // namespace OHOS + +#endif // HARMONYOS_DISTRIBUTED_SCHED_SERVICE_H diff --git a/services/dtbschedmgr/include/distributed_sched_stub.h b/services/dtbschedmgr/include/distributed_sched_stub.h new file mode 100644 index 00000000..781ed157 --- /dev/null +++ b/services/dtbschedmgr/include/distributed_sched_stub.h @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef HARMONYOS_DISTRIBUTED_SCHED_STUB_H +#define HARMONYOS_DISTRIBUTED_SCHED_STUB_H + +#include "distributed_sched_interface.h" +#include "iremote_stub.h" + +namespace OHOS { +namespace DistributedSchedule { +class DistributedSchedStub : public IRemoteStub { +public: + DistributedSchedStub(); + ~DistributedSchedStub(); + int32_t OnRemoteRequest(uint32_t code, + MessageParcel& data, MessageParcel& reply, MessageOption &option) override; +private: + bool EnforceInterfaceToken(MessageParcel& data); + int32_t StartRemoteAbilityInner(MessageParcel& data, MessageParcel& reply); + int32_t StartAbilityFromRemoteInner(MessageParcel& data, MessageParcel& reply); + using DistributedSchedFunc = int32_t(DistributedSchedStub::*)(MessageParcel& data, MessageParcel& reply); + std::map memberFuncMap_; + std::map localMemberFuncMap_; +}; +} // namespace DistributedSchedule +} // namespace OHOS + +#endif // OHOS_DISTRIBUTED_SCHEDULE_STUB_H diff --git a/services/dtbschedmgr/include/dtbschedmgr_log.h b/services/dtbschedmgr/include/dtbschedmgr_log.h new file mode 100644 index 00000000..87370260 --- /dev/null +++ b/services/dtbschedmgr/include/dtbschedmgr_log.h @@ -0,0 +1,311 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef SERVICES_DTBSCHEDMGR_INCLUDE_DTBSCHEDMGR_LOG_H_ +#define SERVICES_DTBSCHEDMGR_INCLUDE_DTBSCHEDMGR_LOG_H_ + +#include "hilog/log_c.h" +#include "hilog/log_cpp.h" + +namespace OHOS { +namespace DistributedSchedule { +static constexpr OHOS::HiviewDFX::HiLogLabel DSCHED_SERVICE_LABEL = {LOG_CORE, 0xD001800, "DSched_Service"}; + +#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 HILOGD(...) (void)OHOS::HiviewDFX::HiLog::Debug(DSCHED_SERVICE_LABEL, __VA_ARGS__) +#define HILOGE(...) (void)OHOS::HiviewDFX::HiLog::Error(DSCHED_SERVICE_LABEL, __VA_ARGS__) +#define HILOGF(...) (void)OHOS::HiviewDFX::HiLog::Fatal(DSCHED_SERVICE_LABEL, __VA_ARGS__) +#define HILOGI(...) (void)OHOS::HiviewDFX::HiLog::Info(DSCHED_SERVICE_LABEL, __VA_ARGS__) +#define HILOGW(...) (void)OHOS::HiviewDFX::HiLog::Warn(DSCHED_SERVICE_LABEL, __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(29360129) for no response when RPC call. + */ + RPC_CALL_NORESPONSE_ERR = 29360129, + /** + * Result(29360130) for not find connect callback. + */ + NO_CONNECT_CALLBACK_ERR = 29360130, + /** + * Result(29360131) for remote invalid parameters. + */ + INVALID_REMOTE_PARAMETERS_ERR = 29360131, + /** + * Result(29360132) for remote device fail to bind ability. + */ + REMOTE_DEVICE_BIND_ABILITY_ERR = 29360132, + /** + * Result(29360133) for remote device fail to unbind ability. + */ + REMOTE_DEVICE_UNBIND_ABILITY_ERR = 29360133, + /** + * Result(29360134) for remote invalid parameters. + */ + REMOTE_FAIL_GET_SHELLINFO_ERR = 29360134, + /** + * Result(29360135) for remote device fail to start ability. + */ + REMOTE_DEVICE_START_ABILITY_ERR = 29360135, + /** + * Result(29360136) for remote device fail to stop ability. + */ + REMOTE_DEVICE_STOP_ABILITY_ERR = 29360136, + /** + * Result(29360137) for reg repeat ability token. + */ + REG_REPEAT_ABILITY_TOKEN_ERR = 29360137, + /** + * Result(29360138) for no ability token. + */ + NO_ABILITY_TOKEN_ERR = 29360138, + /** + * Result(29360139) for no appthread. + */ + NO_APP_THREAD_ERR = 29360139, + /** + * Result(29360140) for select device continue error. + */ + SELECT_DEVICE_CONTINUE_ERR = 29360140, + /** + * Result(29360141) for dump write file error. + */ + DMS_WRITE_FILE_FAILED_ERR = 29360141, + /** + * Result(29360142) for notify app the bind remote service's device is offline. + */ + DEVICE_OFFLINE_ERR = 29360142, + /** + * Result(29360143) for not find hitrace id. + */ + NO_HITRACE_RECORD_ERR = 29360143, + /** + * Result(29360144) for get local deviceid fail. + */ + GET_LOCAL_DEVICE_ERR = 29360144, + /** + * Result(29360145) for get local deviceid fail. + */ + GET_DATAABILITY_ERR = 29360145, + /** + * Result(29360146) for DistributedSched Service Publish Exception. + */ + DMS_PUBLISH_EXCEPTION = 29360146, + /** + * Result(29360147) for DistributedSched Storage Exception. + */ + DMS_GET_STORAGE_EXCEPTION = 29360147, + /** + * Result(29360148) for DistributedSched Service Get System Ability Manager Exception. + */ + DMS_GET_SAMGR_EXCEPTION = 29360148, + /** + * Result(29360149) for DistributedSched Service IPC call noresponse error. + */ + IPC_CALL_NORESPONSE_ERR = 29360149, + /** + * Result(29360150) for DistributedSched Service call bundle manger service error. + */ + BUNDLE_MANAGER_SERVICE_ERR = 29360150, + /** + * Result(29360151) for DistributedSched Service call distributed manger error. + */ + DISTRIBUTED_MANAGER_ERR = 29360151, + /** + * Result(29360152) for DistributedSched Service NotifyCompleteContinuation failed. + */ + NOTIFYCOMPLETECONTINUATION_FAILED = 29360152, + /** + * Result(29360153) for DistributedSched Service Continue Ability Timeout Error. + */ + CONTINUE_ABILITY_TIMEOUT_ERR = 29360153, + /** + * Result(29360154) for DistributedSched Service Notify Complete Continuation abilityToken null. + */ + ABILITYTOKEN_NULL = 29360154, + /** + * Result(29360155) for get device list fail. + */ + GET_DEVICE_LIST_ERR = 29360155, + /** + * Result(29360156) for notify ability install error. + */ + NOTIFY_ABILITY_INSTALL_ERR = 29360156, + /** + * Result(29360157) for permission denied. + */ + DMS_PERMISSION_DENIED = 29360157, + /** + * Result(29360158) for notify ability free install. + */ + NOTIFY_ABILITY_FREE_INSTALL = 29360158, + /** + * Result(29360159) for notify app invalid uid. + */ + BIND_ABILITY_UID_INVALID_ERR = 29360159, + /** + * Result(29360160) for notify app happen connect leak. + */ + BIND_ABILITY_LEAK_ERR = 29360160, + /** + * Result(29360161) for can not service registry. + */ + NOT_FIND_SERVICE_REGISTRY = 29360161, + /** + * Result(29360162) for can not get service. + */ + NOT_FIND_SERVICE_PROXY = 29360162, + /** + * Result(29360163) for IPC Send Request to EMUI DEF fail. + */ + SEND_REQUEST_DEF_FAIL = 29360163, + /** + * Result(29360164) for BMS can not find the specified AA. + */ + CAN_NOT_FOUND_AA_ERR = 29360164, + /** + * Result(29360165) for DMS can not register device state callback. + */ + REGISTER_DEVICE_STATE_CALLBACK_ERR = 29360165, + /** + * Result(29360166) for DMS can not unregister device state callback. + */ + UNREGISTER_DEVICE_STATE_CALLBACK_ERR = 29360166, + /** + * Result(29360167) for DMS can not start slave device FA. + */ + START_SLAVE_FA_ERR = 29360167, + /** + * Result(29360168) for DMS can not get dmsproxy handle. + */ + GET_DMSPROXY_HANDLE_FAIL = 29360168, + /** + * Result(29360169) for dmsproxy service exception. + */ + DMSPROXY_SERVICE_ERR = 29360169, + /** + * Result(29360170) for softbus service unavailable. + */ + SOFTBUS_SERVICE_ERR = 29360170, + /** + * Result(29360171) for softbus register callback fail. + */ + SOFTBUS_REGISTER_CALLBACK_ERR = 29360171, + /** + * Result(29360172) for get DPermission sa fail. + */ + GET_DISTRIBUTED_PERMISSION_SA_ERR = 29360172, + /** + * Result(29360173) for get BMS sa fail. + */ + GET_BUNDLE_MANAGER_ERR = 29360173, + /** + * Result(29360174) for get remote dms fail. + */ + GET_REMOTE_DMS_FAIL = 29360174, + /** + * Result(29360175) for account access permission check failed. + */ + DMS_ACCOUNT_ACCESS_PERMISSION_DENIED = 29360175, + /** + * Result(29360176) for component access permission check failed. + */ + DMS_COMPONENT_ACCESS_PERMISSION_DENIED = 29360176, + /** + * Result(29360177) for distributed communication permission check failed. + */ + DMS_DISTRIBUTED_COMMUNICATION_PERMISSION_DENIED = 29360177, + /** + * Result(29360178) for osd function not support. + */ + TASK_OSD_NOT_SUPPORTED = 29360178, + /** + * Result(29360179) for osd switch is off. + */ + TASK_OSD_NOT_ENABLED = 29360179, + /** + * Result(29360180) for osd switch is on. + */ + TASK_OSD_ENABLED = 29360180, + /** + * Result(29360181) for front app check failed. + */ + CHECK_FRONT_APP_FAIL = 29360181, + /** + * Result(29360182) for ble connected. + */ + BLE_CONNECTED = 29360182, + /** + * Result(29360183) for open p2p session failed. + */ + OPENP2PSESSION_FAILED = 29360183, + /** + * Result(29360184) for notify task change listener failed. + */ + TASK_NOTIFY_CHANGE_LISTENER_ERR = 29360184, + /** + * Result(29360185) for subscribe data storage change failed. + */ + TASK_SUBSCRIBE_DATA_STORAGE_ERR = 29360185, + /** + * Result(29360186) for sync snapshot failed. + */ + TASK_SYNC_SNAPSHOT_ERR = 29360186, + /** + * Result(29360187) for sync task info list failed. + */ + TASK_SYNC_TASK_INFO_LIST_ERR = 29360187, + /** + * Result(29360188) for distributed communication permission check failed. + */ + REMOTE_DISTRIBUTED_COMMUNICATION_PERMISSION_DENIED = 29360188 +}; + +} // namespace DistributedSchedule +} // namespace OHOS +#endif //SERVICES_DTBSCHEDMGR_INCLUDE_DTBSCHEDMGR_LOG_H_ diff --git a/services/dtbschedmgr/src/distributed_sched_proxy.cpp b/services/dtbschedmgr/src/distributed_sched_proxy.cpp new file mode 100644 index 00000000..604cab79 --- /dev/null +++ b/services/dtbschedmgr/src/distributed_sched_proxy.cpp @@ -0,0 +1,67 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "distributed_sched_proxy.h" +#include "dtbschedmgr_log.h" +#include "ipc_types.h" +#include "parcel_helper.h" +#include "string_ex.h" + +using namespace std; +using namespace OHOS::AAFwk; + +namespace OHOS { +namespace DistributedSchedule { +namespace { +const std::u16string DMS_PROXY_INTERFACE_TOKEN = u"ohos.distributedschedule.accessToken"; +} +int32_t DistributedSchedProxy::StartRemoteAbility(const OHOS::AAFwk::Want& userWant, + OHOS::AAFwk::Want& innerWant, int32_t requestCode) +{ + sptr remote = Remote(); + if (remote == nullptr){ + return ERR_NULL_OBJECT; + } + MessageParcel data; + if(!data.WriteInterfaceToken(DMS_PROXY_INTERFACE_TOKEN)) { + return ERR_FLATTEN_OBJECT; + } + PARCEL_WRITE_HELPER(data, Parcelable, &userWant); + PARCEL_WRITE_HELPER(data, Parcelable, &innerWant); + PARCEL_WRITE_HELPER(data, Int32, requestCode); + MessageParcel reply; + PARCEL_TRANSACT_SYNC_RET_INT(remote,START_REMOTE_ABILITY,data,reply); +} + +int32_t DistributedSchedProxy::StartAbilityFromRemote(const OHOS::AAFwk::Want& userWant, + OHOS::AAFwk::Want& innerWant,int32_t requestCode) +{ + sptr remote = Remote(); + if (remote == nullptr){ + return ERR_NULL_OBJECT; + } + MessageParcel data; + if(!data.WriteInterfaceToken(DMS_PROXY_INTERFACE_TOKEN)) { + return ERR_FLATTEN_OBJECT; + } + PARCEL_WRITE_HELPER(data, Parcelable, &userWant); + PARCEL_WRITE_HELPER(data, Parcelable, &innerWant); + PARCEL_WRITE_HELPER(data, Int32, requestCode); + MessageParcel reply; + PARCEL_TRANSACT_SYNC_RET_INT(remote,START_ABILITY_FROM_REMOTE,data,reply); +} +} // namespace DistributedSchedule +} // namespace OHOS + diff --git a/services/dtbschedmgr/src/distributed_sched_service.cpp b/services/dtbschedmgr/src/distributed_sched_service.cpp new file mode 100644 index 00000000..8284695a --- /dev/null +++ b/services/dtbschedmgr/src/distributed_sched_service.cpp @@ -0,0 +1,124 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "distributed_sched_service.h" + +#include +#include + +#include "ability_manager_client.h" +#include "dtbschedmgr_log.h" +#include "element_name.h" +#include "ipc_skeleton.h" +#include "iservice_registry.h" +#include "string_ex.h" +#include "system_ability_definition.h" + +namespace OHOS { +namespace DistributedSchedule { +using namespace AAFwk; +using namespace AppExecFwk; +namespace { + const std::string PARAM_CALLING_UID = "dms.extra.param.key.callingUid"; + const std::string PARAM_CALLING_PID = "dms.extra.param.key.callingPid"; + const std::string PARAM_CALLING_NETWORK_ID = "dms.extra.param.key.srcNetworkId"; +} + +IMPLEMENT_SINGLE_INSTANCE(DistributedSchedService); + +const bool REGISTER_RESULT = SystemAbility::MakeAndRegisterAbility(&DistributedSchedService::GetInstance()); + +DistributedSchedService::DistributedSchedService() : SystemAbility(DISTRIBUTED_SCHED_SA_ID, true) +{ +} + +void DistributedSchedService::OnStart() +{ + if (!Init()) { + HILOGE("failed to init DistributedSchedService"); + return; + } + HILOGI("DistributedSchedService::OnStart start service success."); +} + +bool DistributedSchedService::Init() +{ + HILOGD("DistributedSchedService::Init ready to init."); + if (!registerToService_) { + bool ret = Publish(this); + if (!ret) { + HILOGE("DistributedSchedService::Init Publish failed!"); + return false; + } + registerToService_ = true; + } + HILOGD("DistributedSchedService::Init init success."); + return true; +} + +void DistributedSchedService::OnStop() +{ + HILOGD("DistributedSchedService::OnStop ready to stop service."); + registerToService_ = false; +} + +int32_t DistributedSchedService::StartRemoteAbility(const OHOS::AAFwk::Want& userWant, + OHOS::AAFwk::Want& innerWant, int32_t requestCode) +{ + std::string deviceId = userWant.GetElement().GetDeviceID(); + sptr remoteDms = GetRemoteDms(deviceId); + if (remoteDms == nullptr) { + HILOGE("StartRemoteAbility DMS get remoteDms failed"); + return INVALID_PARAMETERS_ERR; + } + HILOGI("[PerformanceTest] DistributedSchedService StartRemoteAbility transact begin"); + int32_t result = remoteDms->StartAbilityFromRemote(userWant, innerWant, requestCode); + HILOGI("[PerformanceTest] DistributedSchedService StartRemoteAbility transact end"); + return result; +} + +int32_t DistributedSchedService::StartAbilityFromRemote(const OHOS::AAFwk::Want& userWant, + OHOS::AAFwk::Want& innerWant, int32_t requestCode) +{ + ErrCode err = AAFwk::AbilityManagerClient::GetInstance()->StartAbility(userWant, requestCode); + if (err != ERR_OK) { + HILOGE("StartAbilityFromRemote is failed %{public}d", err); + } + return err; +} + +sptr DistributedSchedService::GetRemoteDms(const std::string& remoteDeviceId) +{ + if (remoteDeviceId.empty()) { + HILOGE("GetRemoteDms remoteDeviceId is empty"); + return nullptr; + } + HILOGD("GetRemoteDms connect deviceid is %s", remoteDeviceId.c_str()); + auto samgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); + if (samgr == nullptr) { + HILOGE("GetRemoteDms failed to connect to systemAbilityMgr!"); + return nullptr; + } + HILOGD("[PerformanceTest] DistributedSchedService GetRemoteDms begin"); + auto object = samgr->CheckSystemAbility(1401/*,remoteDeviceId*/); //TODO + HILOGD("[PerformanceTest] DistributedSchedService GetRemoteDms end"); + if (object == nullptr) { + HILOGE("GetRemoteDms failed to get remote DistributedSched %{private}s", remoteDeviceId.c_str()); + return nullptr; + } + return iface_cast(object); +} +} //namespace DistributedSchedule +} //namespace OHOS \ No newline at end of file diff --git a/services/dtbschedmgr/src/distributed_sched_stub.cpp b/services/dtbschedmgr/src/distributed_sched_stub.cpp new file mode 100644 index 00000000..03d8532a --- /dev/null +++ b/services/dtbschedmgr/src/distributed_sched_stub.cpp @@ -0,0 +1,117 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "distributed_sched_stub.h" +#include "dtbschedmgr_log.h" +#include "ipc_skeleton.h" +#include "message_parcel.h" +#include "parcel_helper.h" + +using namespace std; + +namespace OHOS { +namespace DistributedSchedule { +namespace { + const std::u16string DMS_STUB_INTERFACE_TOKEN = u"ohos.distributedschedule.accessToken"; +} +DistributedSchedStub::DistributedSchedStub() +{ + localMemberFuncMap_[START_REMOTE_ABILITY] = &DistributedSchedStub::StartRemoteAbilityInner; + memberFuncMap_[START_ABILITY_FROM_REMOTE] = &DistributedSchedStub::StartAbilityFromRemoteInner; +} + +DistributedSchedStub::~DistributedSchedStub() +{ + memberFuncMap_.clear(); + localMemberFuncMap_.clear(); +} + +int32_t DistributedSchedStub::OnRemoteRequest(uint32_t code, + MessageParcel& data, MessageParcel &reply, MessageOption &option) +{ + bool IsLocalCalling = IPCSkeleton::IsLocalCalling(); + HILOGI("DistributedSchedStub::OnReceived, code = %{public}d, flags = %{public}d IsLocalCalling = %{public}d.", code, + option.GetFlags(), IsLocalCalling); + auto localFuncIt = localMemberFuncMap_.find(code); + if (localFuncIt != localMemberFuncMap_.end()) { + auto memberFunc = localFuncIt->second; + if (memberFunc != nullptr) { + return (this->*memberFunc)(data, reply); + } + } + auto distributedFuncIt = memberFuncMap_.find(code); + if (distributedFuncIt != memberFuncMap_.end()) { + auto memberFunc = distributedFuncIt->second; + if (memberFunc != nullptr) { + return (this->*memberFunc)(data, reply); + } + } + HILOGW("DistributedSchedStub: default case, need check."); + return IPCObjectStub::OnRemoteRequest(code, data, reply, option); +} + +int32_t DistributedSchedStub::StartRemoteAbilityInner(MessageParcel& data, MessageParcel& reply) +{ + if (!EnforceInterfaceToken(data)) { + HILOGW("DistributedSchedStub:: StartRemoteAbilityInner interface token check failed!"); + return DMS_PERMISSION_DENIED; + } + shared_ptr userWant(data.ReadParcelable()); + if (userWant == nullptr) { + HILOGW("DistributedSchedStub:: START_ABILITY userWant readParcelable failed!"); + return ERR_NULL_OBJECT; + } + shared_ptr innerWant(data.ReadParcelable()); + if (innerWant == nullptr) { + HILOGW("DistributedSchedStub:: START_ABILITY innerWant readParcelable failed!"); + return ERR_NULL_OBJECT; + } + int32_t requestCode = 0; + PARCEL_READ_HELPER(data, Int32, requestCode); + int32_t result = StartRemoteAbility(*userWant, *innerWant, requestCode); + HILOGI("DistributedSchedStub:: StartRemoteAbilityInner result = %{public}d", result); + PARCEL_WRITE_REPLY_NOERROR(reply, Int32, result); +} + +int32_t DistributedSchedStub::StartAbilityFromRemoteInner(MessageParcel& data, MessageParcel& reply) +{ + if (!EnforceInterfaceToken(data)) { + HILOGW("DistributedSchedStub:: StartAbilityFromRemoteInner interface token check failed!"); + return DMS_PERMISSION_DENIED; + } + shared_ptr userWant(data.ReadParcelable()); + if (userWant == nullptr) { + HILOGW("DistributedSchedStub:: StartAbilityFromRemoteInner userWant readParcelable failed!"); + return ERR_NULL_OBJECT; + } + shared_ptr innerWant(data.ReadParcelable()); + if (innerWant == nullptr) { + HILOGW("DistributedSchedStub:: StartAbilityFromRemoteInner innerWant readParcelable failed!"); + return ERR_NULL_OBJECT; + } + int32_t requestCode = 0; + PARCEL_READ_HELPER(data, Int32, requestCode); + int32_t result = StartAbilityFromRemote(*userWant, *innerWant, requestCode); + HILOGI("DistributedSchedStub:: StartAbilityFromRemoteInner result = %{public}d", result); + return ERR_NONE; +} + +bool DistributedSchedStub::EnforceInterfaceToken(MessageParcel& data) +{ + u16string interfaceToken = data.ReadInterfaceToken(); + return interfaceToken == DMS_STUB_INTERFACE_TOKEN; +} +} //namespace DistributedSchedule +} //namespace OHOS