diff --git a/interfaces/inner_kits/native_cpp/BUILD.gn b/interfaces/inner_kits/native_cpp/BUILD.gn index 2068a5585b19c581039241a6e5110ae529ed7035..566081064ff415b9fa55b0f502473ee9484e158e 100644 --- a/interfaces/inner_kits/native_cpp/BUILD.gn +++ b/interfaces/inner_kits/native_cpp/BUILD.gn @@ -188,6 +188,7 @@ if (defined(ohos_lite)) { "src/ipc/standard/ipc_client_stub.cpp", "src/ipc/standard/ipc_cmd_parser.cpp", "src/notify/device_manager_notify.cpp", + "src/notify/device_manager_notify_service.cpp", ] public_configs = [ ":devicemanagersdk_config" ] @@ -200,7 +201,10 @@ if (defined(ohos_lite)) { "LOG_DOMAIN=0xD004111", ] - deps = [ "${json_path}:devicemanagerjson" ] + deps = [ + "${json_path}:devicemanagerjson", + "${devicemanager_path}/services/service:device_manager_ipc", + ] external_deps = [ "access_token:libaccesstoken_sdk", diff --git a/interfaces/inner_kits/native_cpp/include/notify/device_manager_notify_service.h b/interfaces/inner_kits/native_cpp/include/notify/device_manager_notify_service.h new file mode 100644 index 0000000000000000000000000000000000000000..c0f0bf0d8b45cc8dd2b0e2811d0b36d846334c23 --- /dev/null +++ b/interfaces/inner_kits/native_cpp/include/notify/device_manager_notify_service.h @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2025 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 DEVICE_MANAGER_NOTIFY_SERVICE_H +#define DEVICE_MANAGER_NOTIFY_SERVICE_H +#include "device_manager_ipc_stub.h" +namespace OHOS { +namespace DistributedHardware { +class DeviceManagerNotifyService : public DeviceManagerIpcStub { +public: + DeviceManagerNotifyService() = default; + ~DeviceManagerNotifyService() = default; + ErrCode ServerPublishFinish( + const std::string &pkgName, + int32_t publishId, + int32_t publishResult); +}; + +} +} +#endif // DEVICE_MANAGER_NOTIFY_SERVICE_H \ No newline at end of file diff --git a/interfaces/inner_kits/native_cpp/src/ipc/standard/ipc_client_manager.cpp b/interfaces/inner_kits/native_cpp/src/ipc/standard/ipc_client_manager.cpp index f912db8d9b4b7a98b7e23f8ff8101002f7bfa4fc..cf93d649086850bd9b9476da49370708e758a754 100644 --- a/interfaces/inner_kits/native_cpp/src/ipc/standard/ipc_client_manager.cpp +++ b/interfaces/inner_kits/native_cpp/src/ipc/standard/ipc_client_manager.cpp @@ -31,7 +31,8 @@ #include "iservice_registry.h" #include "system_ability_definition.h" #include - +#include "idevice_manager_ipc.h" +#include "device_manager_notify_service.h" namespace OHOS { namespace DistributedHardware { void DmDeathRecipient::OnRemoteDied(const wptr &remote) @@ -86,6 +87,7 @@ int32_t IpcClientManager::Init(const std::string &pkgName) } sptr listener = sptr(new IpcClientStub()); + sptr listener2 = sptr(new (std::nothrow) DeviceManagerNotifyService()); std::shared_ptr req = std::make_shared(); std::shared_ptr rsp = std::make_shared(); req->SetPkgName(pkgName); @@ -100,6 +102,9 @@ int32_t IpcClientManager::Init(const std::string &pkgName) return ret; } dmListener_[pkgName] = listener; + // 打印 dmListener_ 的内容和地址 + LOGI("dmListener_ updated: pkgName = %{public}s, listener address = 0x%lx", + pkgName.c_str(), static_cast(reinterpret_cast(listener.GetRefPtr()))); LOGI("completed, pkgName: %{public}s", pkgName.c_str()); return DM_OK; } diff --git a/interfaces/inner_kits/native_cpp/src/notify/device_manager_notify_service.cpp b/interfaces/inner_kits/native_cpp/src/notify/device_manager_notify_service.cpp new file mode 100644 index 0000000000000000000000000000000000000000..ef72bd52a408b83ce9f8a6507de7c6ee5c4e33ef --- /dev/null +++ b/interfaces/inner_kits/native_cpp/src/notify/device_manager_notify_service.cpp @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2025 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 +#include "device_manager_notify_service.h" +#include "device_manager_notify.h" +#include "dm_log.h" +namespace OHOS { +namespace DistributedHardware { +ErrCode DeviceManagerNotifyService::ServerPublishFinish( + const std::string &pkgName, + int32_t publishId, + int32_t publishResult) +{ + LOGI("DM IDL DMNS::ServerPublishFinish : pkgName: %{public}s, publishId: %{public}d, publishResult: %{public}d", + pkgName.c_str(), publishResult, publishResult); + return 0; +} +} +} \ No newline at end of file diff --git a/services/service/BUILD.gn b/services/service/BUILD.gn index c6d338d2fafeea7f9daae5f86fddc1164a82c1e5..4869b48b507c79e06759f79e290c7cc2a2f9dd95 100644 --- a/services/service/BUILD.gn +++ b/services/service/BUILD.gn @@ -15,6 +15,7 @@ if (defined(ohos_lite)) { import("//build/lite/config/component/lite_component.gni") } else { import("//build/ohos.gni") + import("//build/config/components/idl_tool/idl.gni") } import("//foundation/distributedhardware/device_manager/device_manager.gni") @@ -126,6 +127,32 @@ if (defined(ohos_lite)) { deps = [] } } else { +idl_gen_interface("device_manager_interface") { +src_idl = rebase_path("IDeviceManagerIpc.idl") +log_tag = "devicemanagerservice" +log_domainid = "0xD004110" +} + +ohos_source_set("device_manager_ipc") { +sanitize = { + debug = false + cfi = true + cfi_cross_dso = true +} +output_values = get_target_outputs(":device_manager_interface") +sources = [] +sources += filter_include(output_values, [ "*.cpp" ]) +public_configs = [ ":devicemanagerservice_config" ] +deps = [ ":device_manager_interface" ] +external_deps = [ + "c_utils:utils", + "hilog:libhilog", + "hitrace:hitrace_meter", + "ipc:ipc_core", +] +subsystem_name = "distributedhardware" +part_name = "device_manager" +} config("devicemanagerservice_config") { include_dirs = [ "include", @@ -158,6 +185,7 @@ if (defined(ohos_lite)) { "${utils_path}/include/kvadapter", "${utils_path}/include/timer", "${json_path}/include", + "${target_gen_dir}", ] } config("cflags_config") { @@ -237,9 +265,11 @@ if (defined(ohos_lite)) { "HI_LOG_ENABLE", "DH_LOG_TAG=\"devicemanagerservice\"", "LOG_DOMAIN=0xD004110", + "private = public", ] deps = [ + ":device_manager_ipc", "${devicemanager_path}/commondependency:devicemanagerdependency", "${devicemanager_path}/radar:devicemanagerradar", "${devicemanager_path}/services/implementation:devicemanagerserviceimpl", @@ -378,11 +408,13 @@ if (defined(ohos_lite)) { defines = [ "HI_LOG_ENABLE", - "DH_LOG_TAG=\"devicemanagerservice\"", + "DH_LOG_TAG=\"devicemanagerserviceIpc\"", "LOG_DOMAIN=0xD004110", + "private = public", ] deps = [ + ":device_manager_ipc", "${devicemanager_path}/commondependency:devicemanagerdependency", "${devicemanager_path}/radar:devicemanagerradar", "${devicemanager_path}/services/implementation:devicemanagerserviceimpl", diff --git a/services/service/IDeviceManagerIpc.idl b/services/service/IDeviceManagerIpc.idl new file mode 100644 index 0000000000000000000000000000000000000000..13bcc9965a2bbb7aacadb17e2b290988062b005a --- /dev/null +++ b/services/service/IDeviceManagerIpc.idl @@ -0,0 +1,17 @@ +/* + * Copyright (c) 2025 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. + */ +interface OHOS.DistributedHardware.IDeviceManagerIpc { +[ipccode 17] void ServerPublishFinish([in] String pkgName, [in] int publishId, [in] int publishResult); +} \ No newline at end of file diff --git a/services/service/include/device_manager_service_listener.h b/services/service/include/device_manager_service_listener.h index fbf03d22ab075989afc2b3f3cefeca6d724a6801..1038011672c7ec5547b24fbee1e5b0050a7614ed 100644 --- a/services/service/include/device_manager_service_listener.h +++ b/services/service/include/device_manager_service_listener.h @@ -33,12 +33,12 @@ #include "ipc_server_listener.h" #endif #include "ipc_notify_device_state_req.h" - +#include "idevice_manager_ipc.h" namespace OHOS { namespace DistributedHardware { class DM_EXPORT DeviceManagerServiceListener : public IDeviceManagerServiceListener { public: - DeviceManagerServiceListener() {}; + DeviceManagerServiceListener(); virtual ~DeviceManagerServiceListener() {}; void OnDeviceStateChange(const ProcessInfo &processInfo, const DmDeviceState &state, diff --git a/services/service/include/ipc/standard/ipc_server_stub.h b/services/service/include/ipc/standard/ipc_server_stub.h index 4756323015470d3d3237c4062accb45a41c08fe8..769a9f03137e8f51160511620e3d26261bb3b758 100644 --- a/services/service/include/ipc/standard/ipc_server_stub.h +++ b/services/service/include/ipc/standard/ipc_server_stub.h @@ -32,7 +32,7 @@ #include "dm_device_info.h" #include "dm_single_instance.h" - +#include "idevice_manager_ipc.h" namespace OHOS { namespace DistributedHardware { enum class ServiceRunningState { STATE_NOT_START, STATE_RUNNING }; @@ -87,7 +87,7 @@ public: * @tc.desc: Register DeviceManager Listener of the IpcServerStub * @tc.type: FUNC */ - int32_t RegisterDeviceManagerListener(const ProcessInfo &processInfo, sptr listener); + int32_t RegisterDeviceManagerListener(const ProcessInfo &processInfo, sptr listener); /** * @tc.name: IpcServerStub::UnRegisterDeviceManagerListener @@ -115,8 +115,7 @@ public: * @tc.desc: Get DmListener of the IpcServerStub * @tc.type: FUNC */ - const sptr GetDmListener(ProcessInfo processInfo) const; - + const sptr GetDmListener(ProcessInfo processInfo) const; /** * @tc.name: IpcServerStub::GetDmListenerPkgName * @tc.desc: Get DmListener PkgName of the IpcServerStub @@ -164,7 +163,7 @@ private: ServiceRunningState state_; mutable std::mutex listenerLock_; std::map> appRecipient_; - std::map> dmListener_; + std::map> dmListener_; std::set systemSA_; int64_t startBeginTime_ = 0; }; diff --git a/services/service/src/device_manager_service_listener.cpp b/services/service/src/device_manager_service_listener.cpp index d1d0a84b8377d0256468ec5d844b975814030128..3d630d27b2274e45c48b0559825915e58f9e58b6 100644 --- a/services/service/src/device_manager_service_listener.cpp +++ b/services/service/src/device_manager_service_listener.cpp @@ -59,6 +59,10 @@ std::map DeviceManagerServiceListener::alreadyOnlineP std::unordered_set DeviceManagerServiceListener::highPriorityPkgNameSet_ = { "ohos.deviceprofile", "ohos.distributeddata.service" }; +DeviceManagerServiceListener::DeviceManagerServiceListener() +{ + LOGI("DeviceManagerServiceListener constructor called."); +} void handleExtraData(const DmDeviceInfo &info, DmDeviceBasicInfo &deviceBasicInfo) { cJSON *extraDataJsonObj = cJSON_Parse(info.extraData.c_str()); @@ -277,7 +281,8 @@ void DeviceManagerServiceListener::OnDeviceFound(const ProcessInfo &processInfo, pReq->SetSubscribeId(subscribeId); pReq->SetDeviceInfo(deviceInfo); pReq->SetProcessInfo(processInfo); - ipcServerListener_.SendRequest(SERVER_DEVICE_FOUND, pReq, pRsp); + //ipcServerListener_.SendRequest(SERVER_DEVICE_FOUND, pReq, pRsp); + return; } void DeviceManagerServiceListener::OnDiscoveryFailed(const ProcessInfo &processInfo, uint16_t subscribeId, @@ -291,7 +296,8 @@ void DeviceManagerServiceListener::OnDiscoveryFailed(const ProcessInfo &processI pReq->SetSubscribeId(subscribeId); pReq->SetResult(failedReason); pReq->SetProcessInfo(processInfo); - ipcServerListener_.SendRequest(SERVER_DISCOVER_FINISH, pReq, pRsp); + //ipcServerListener_.SendRequest(SERVER_DISCOVER_FINISH, pReq, pRsp); + return; } void DeviceManagerServiceListener::OnDiscoverySuccess(const ProcessInfo &processInfo, int32_t subscribeId) @@ -304,19 +310,28 @@ void DeviceManagerServiceListener::OnDiscoverySuccess(const ProcessInfo &process pReq->SetSubscribeId((uint16_t)subscribeId); pReq->SetResult(DM_OK); pReq->SetProcessInfo(processInfo); - ipcServerListener_.SendRequest(SERVER_DISCOVER_FINISH, pReq, pRsp); + //ipcServerListener_.SendRequest(SERVER_DISCOVER_FINISH, pReq, pRsp); + return; } void DeviceManagerServiceListener::OnPublishResult(const std::string &pkgName, int32_t publishId, int32_t publishResult) { - LOGI("OnPublishResult : %{public}d", publishResult); + LOGI("DM IDL DMSL::OnPublishResult : pkgName: %{public}s, publishId: %{public}d, publishResult: %{public}d", + pkgName.c_str(), publishResult, publishResult); std::shared_ptr pReq = std::make_shared(); std::shared_ptr pRsp = std::make_shared(); - pReq->SetPkgName(pkgName); - pReq->SetPublishId(publishId); - pReq->SetResult(publishResult); - ipcServerListener_.SendRequest(SERVER_PUBLISH_FINISH, pReq, pRsp); + // ProcessInfo processInfo; + // processInfo.pkgName = pkgName; + // sptr deviceManagerIpc = IpcServerStub::GetInstance().GetDmListener(processInfo); + // if (deviceManagerIpc == nullptr) { + // LOGE("cannot get listener for package:%{public}s.", processInfo.pkgName.c_str()); + // return; + // } + // LOGI("deviceManagerIpc address: 0x%lx for pkgName: %{public}s", + // static_cast(reinterpret_cast(deviceManagerIpc.GetRefPtr())), + // processInfo.pkgName.c_str()); + // deviceManagerIpc->ServerPublishFinish(pkgName, publishId, publishResult); } void DeviceManagerServiceListener::OnAuthResult(const ProcessInfo &processInfo, const std::string &deviceId, @@ -339,7 +354,8 @@ void DeviceManagerServiceListener::OnAuthResult(const ProcessInfo &processInfo, pReq->SetStatus(status); pReq->SetReason(reason); pReq->SetProcessInfo(processInfo); - ipcServerListener_.SendRequest(SERVER_AUTH_RESULT, pReq, pRsp); + //ipcServerListener_.SendRequest(SERVER_AUTH_RESULT, pReq, pRsp); + return; } void DeviceManagerServiceListener::OnUiCall(const ProcessInfo &processInfo, std::string ¶mJson) @@ -351,7 +367,8 @@ void DeviceManagerServiceListener::OnUiCall(const ProcessInfo &processInfo, std: pReq->SetPkgName(processInfo.pkgName); pReq->SetJsonParam(paramJson); pReq->SetProcessInfo(processInfo); - ipcServerListener_.SendRequest(SERVER_DEVICE_FA_NOTIFY, pReq, pRsp); + //ipcServerListener_.SendRequest(SERVER_DEVICE_FA_NOTIFY, pReq, pRsp); + return; } void DeviceManagerServiceListener::OnCredentialResult(const ProcessInfo &processInfo, int32_t action, @@ -365,7 +382,8 @@ void DeviceManagerServiceListener::OnCredentialResult(const ProcessInfo &process pReq->SetCredentialAction(action); pReq->SetCredentialResult(resultInfo); pReq->SetProcessInfo(processInfo); - ipcServerListener_.SendRequest(SERVER_CREDENTIAL_RESULT, pReq, pRsp); + //ipcServerListener_.SendRequest(SERVER_CREDENTIAL_RESULT, pReq, pRsp); + return; } void DeviceManagerServiceListener::OnBindResult(const ProcessInfo &processInfo, const PeerTargetId &targetId, @@ -391,7 +409,8 @@ void DeviceManagerServiceListener::OnBindResult(const ProcessInfo &processInfo, pReq->SetStatus(status); pReq->SetContent(content); pReq->SetProcessInfo(processInfo); - ipcServerListener_.SendRequest(BIND_TARGET_RESULT, pReq, pRsp); + //ipcServerListener_.SendRequest(BIND_TARGET_RESULT, pReq, pRsp); + return; } void DeviceManagerServiceListener::OnUnbindResult(const ProcessInfo &processInfo, const PeerTargetId &targetId, @@ -413,7 +432,8 @@ void DeviceManagerServiceListener::OnUnbindResult(const ProcessInfo &processInfo pReq->SetResult(result); pReq->SetContent(content); pReq->SetProcessInfo(processInfo); - ipcServerListener_.SendRequest(UNBIND_TARGET_RESULT, pReq, pRsp); + //ipcServerListener_.SendRequest(UNBIND_TARGET_RESULT, pReq, pRsp); + return; } void DeviceManagerServiceListener::OnPinHolderCreate(const ProcessInfo &processInfo, const std::string &deviceId, @@ -428,7 +448,8 @@ void DeviceManagerServiceListener::OnPinHolderCreate(const ProcessInfo &processI pReq->SetPinType(pinType); pReq->SetPayload(payload); pReq->SetProcessInfo(processInfo); - ipcServerListener_.SendRequest(SERVER_CREATE_PIN_HOLDER, pReq, pRsp); + //ipcServerListener_.SendRequest(SERVER_CREATE_PIN_HOLDER, pReq, pRsp); + return; } void DeviceManagerServiceListener::OnPinHolderDestroy(const ProcessInfo &processInfo, DmPinType pinType, @@ -442,7 +463,8 @@ void DeviceManagerServiceListener::OnPinHolderDestroy(const ProcessInfo &process pReq->SetPinType(pinType); pReq->SetPayload(payload); pReq->SetProcessInfo(processInfo); - ipcServerListener_.SendRequest(SERVER_DESTROY_PIN_HOLDER, pReq, pRsp); + //ipcServerListener_.SendRequest(SERVER_DESTROY_PIN_HOLDER, pReq, pRsp); + return; } void DeviceManagerServiceListener::OnCreateResult(const ProcessInfo &processInfo, int32_t result) @@ -454,7 +476,8 @@ void DeviceManagerServiceListener::OnCreateResult(const ProcessInfo &processInfo pReq->SetPkgName(processInfo.pkgName); pReq->SetResult(result); pReq->SetProcessInfo(processInfo); - ipcServerListener_.SendRequest(SERVER_CREATE_PIN_HOLDER_RESULT, pReq, pRsp); + //ipcServerListener_.SendRequest(SERVER_CREATE_PIN_HOLDER_RESULT, pReq, pRsp); + return; } void DeviceManagerServiceListener::OnDestroyResult(const ProcessInfo &processInfo, int32_t result) @@ -466,7 +489,8 @@ void DeviceManagerServiceListener::OnDestroyResult(const ProcessInfo &processInf pReq->SetPkgName(processInfo.pkgName); pReq->SetResult(result); pReq->SetProcessInfo(processInfo); - ipcServerListener_.SendRequest(SERVER_DESTROY_PIN_HOLDER_RESULT, pReq, pRsp); + //ipcServerListener_.SendRequest(SERVER_DESTROY_PIN_HOLDER_RESULT, pReq, pRsp); + return; } void DeviceManagerServiceListener::OnPinHolderEvent(const ProcessInfo &processInfo, DmPinHolderEvent event, @@ -482,7 +506,8 @@ void DeviceManagerServiceListener::OnPinHolderEvent(const ProcessInfo &processIn pReq->SetResult(result); pReq->SetContent(content); pReq->SetProcessInfo(processInfo); - ipcServerListener_.SendRequest(SERVER_ON_PIN_HOLDER_EVENT, pReq, pRsp); + //ipcServerListener_.SendRequest(SERVER_ON_PIN_HOLDER_EVENT, pReq, pRsp); + return; } #if !(defined(__LITEOS_M__) || defined(LITE_DEVICE)) int32_t DeviceManagerServiceListener::ConvertUdidHashToAnoyAndSave(const std::string &pkgName, DmDeviceInfo &deviceInfo) @@ -545,7 +570,8 @@ void DeviceManagerServiceListener::OnDeviceTrustChange(const std::string &udid, pReq->SetUuid(uuid); pReq->SetAuthForm(authForm); pReq->SetProcessInfo(item); - ipcServerListener_.SendRequest(REMOTE_DEVICE_TRUST_CHANGE, pReq, pRsp); + //ipcServerListener_.SendRequest(REMOTE_DEVICE_TRUST_CHANGE, pReq, pRsp); + return; } } @@ -583,7 +609,8 @@ void DeviceManagerServiceListener::OnDeviceScreenStateChange(const ProcessInfo & GetNotifyProcessInfoByUserId(userId, DmCommonNotifyEvent::REG_DEVICE_SCREEN_STATE); for (const auto &item : processInfoVec) { SetDeviceScreenInfo(pReq, item, devInfo); - ipcServerListener_.SendRequest(SERVER_DEVICE_SCREEN_STATE_NOTIFY, pReq, pRsp); + //ipcServerListener_.SendRequest(SERVER_DEVICE_SCREEN_STATE_NOTIFY, pReq, pRsp); + return; } } else { std::shared_ptr pReq = std::make_shared(); @@ -593,7 +620,8 @@ void DeviceManagerServiceListener::OnDeviceScreenStateChange(const ProcessInfo & processInfoVec.push_back(processInfo); for (const auto &item : processInfoVec) { SetDeviceScreenInfo(pReq, item, devInfo); - ipcServerListener_.SendRequest(SERVER_DEVICE_SCREEN_STATE_NOTIFY, pReq, pRsp); + //ipcServerListener_.SendRequest(SERVER_DEVICE_SCREEN_STATE_NOTIFY, pReq, pRsp); + return; } } } @@ -631,7 +659,8 @@ void DeviceManagerServiceListener::OnCredentialAuthStatus(const ProcessInfo &pro pReq->SetErrCode(errcode); pReq->SetPkgName(item.pkgName); pReq->SetProcessInfo(item); - ipcServerListener_.SendRequest(SERVICE_CREDENTIAL_AUTH_STATUS_NOTIFY, pReq, pRsp); + //ipcServerListener_.SendRequest(SERVICE_CREDENTIAL_AUTH_STATUS_NOTIFY, pReq, pRsp); + return; } } @@ -682,7 +711,8 @@ void DeviceManagerServiceListener::OnSinkBindResult(const ProcessInfo &processIn pReq->SetResult(result); pReq->SetStatus(status); pReq->SetContent(content); - ipcServerListener_.SendRequest(SINK_BIND_TARGET_RESULT, pReq, pRsp); + //ipcServerListener_.SendRequest(SINK_BIND_TARGET_RESULT, pReq, pRsp); + return; } std::vector DeviceManagerServiceListener::GetWhiteListSAProcessInfo( @@ -776,7 +806,8 @@ void DeviceManagerServiceListener::ProcessDeviceOnline(const std::vector pRsp = std::make_shared(); for (const auto &it : procInfoVec) { SetDeviceInfo(pReq, it, state, info, deviceBasicInfo); - ipcServerListener_.SendRequest(SERVER_DEVICE_STATE_NOTIFY, pReq, pRsp); + //ipcServerListener_.SendRequest(SERVER_DEVICE_STATE_NOTIFY, pReq, pRsp); + return; } } @@ -839,7 +872,8 @@ void DeviceManagerServiceListener::ProcessAppOnline(const std::vector pRsp = std::make_shared(); ConvertDeviceInfoToDeviceBasicInfo(processInfo.pkgName, item, deviceBasicInfo); SetDeviceInfo(pReq, processInfo, DmDeviceState::DEVICE_STATE_ONLINE, item, deviceBasicInfo); - ipcServerListener_.SendRequest(SERVER_DEVICE_STATE_NOTIFY, pReq, pRsp); + //ipcServerListener_.SendRequest(SERVER_DEVICE_STATE_NOTIFY, pReq, pRsp); + return; } } @@ -962,7 +999,8 @@ void DeviceManagerServiceListener::OnGetDeviceProfileInfoListResult(const Proces #endif pReq->SetResult(code); pReq->SetProcessInfo(processInfo); - ipcServerListener_.SendRequest(GET_DEVICE_PROFILE_INFO_LIST_RESULT, pReq, pRsp); + //ipcServerListener_.SendRequest(GET_DEVICE_PROFILE_INFO_LIST_RESULT, pReq, pRsp); + return; } void DeviceManagerServiceListener::OnGetDeviceIconInfoResult(const ProcessInfo &processInfo, @@ -975,7 +1013,8 @@ void DeviceManagerServiceListener::OnGetDeviceIconInfoResult(const ProcessInfo & pReq->SetDmDeviceIconInfo(dmDeviceIconInfo); pReq->SetResult(code); pReq->SetProcessInfo(processInfo); - ipcServerListener_.SendRequest(GET_DEVICE_ICON_INFO_RESULT, pReq, pRsp); + //ipcServerListener_.SendRequest(GET_DEVICE_ICON_INFO_RESULT, pReq, pRsp); + return; } void DeviceManagerServiceListener::OnSetLocalDeviceNameResult(const ProcessInfo &processInfo, @@ -994,7 +1033,8 @@ void DeviceManagerServiceListener::OnSetLocalDeviceNameResult(const ProcessInfo #else (void) deviceName; #endif - ipcServerListener_.SendRequest(SET_LOCAL_DEVICE_NAME_RESULT, pReq, pRsp); + //ipcServerListener_.SendRequest(SET_LOCAL_DEVICE_NAME_RESULT, pReq, pRsp); + return; } void DeviceManagerServiceListener::OnSetRemoteDeviceNameResult(const ProcessInfo &processInfo, @@ -1008,7 +1048,8 @@ void DeviceManagerServiceListener::OnSetRemoteDeviceNameResult(const ProcessInfo pReq->SetResult(code); pReq->SetProcessInfo(processInfo); (void) deviceName; - ipcServerListener_.SendRequest(SET_REMOTE_DEVICE_NAME_RESULT, pReq, pRsp); + //ipcServerListener_.SendRequest(SET_REMOTE_DEVICE_NAME_RESULT, pReq, pRsp); + return; } std::string DeviceManagerServiceListener::GetLocalDisplayDeviceNameForPrivacy() diff --git a/services/service/src/ipc/standard/ipc_cmd_parser.cpp b/services/service/src/ipc/standard/ipc_cmd_parser.cpp index 58517d1567c15030abaa37ca975a1aa5333b1c8b..12416d1645d53248ea17608136137c46be382e4b 100644 --- a/services/service/src/ipc/standard/ipc_cmd_parser.cpp +++ b/services/service/src/ipc/standard/ipc_cmd_parser.cpp @@ -49,6 +49,8 @@ #if !(defined(__LITEOS_M__) || defined(LITE_DEVICE)) #include "multiple_user_connector.h" #endif +#include "device_manager_ipc_proxy.h" +#include "idevice_manager_ipc.h" namespace OHOS { namespace DistributedHardware { const unsigned int XCOLLIE_TIMEOUT_S = 5; @@ -464,7 +466,10 @@ ON_IPC_CMD(REGISTER_DEVICE_MANAGER_LISTENER, MessageParcel &data, MessageParcel CancelXcollieTimer(timerId); return ERR_DM_POINT_NULL; } - sptr callback(new IpcServerClientProxy(listener)); + // 打印 listener 的地址 + LOGI("Listener address: 0x%lx, pkgName: %s", static_cast(reinterpret_cast(listener.GetRefPtr())), + pkgName.c_str()); + sptr callback(new DeviceManagerIpcProxy(listener)); if (callback == nullptr) { LOGE("create ipc server client proxy failed."); CancelXcollieTimer(timerId); diff --git a/services/service/src/ipc/standard/ipc_server_listener.cpp b/services/service/src/ipc/standard/ipc_server_listener.cpp index b40ee0a405d49b3ee8a084a2eb4ea28a5e810c6e..b71ccaea0c646278baa150e8d590a8949cd7428e 100644 --- a/services/service/src/ipc/standard/ipc_server_listener.cpp +++ b/services/service/src/ipc/standard/ipc_server_listener.cpp @@ -36,12 +36,13 @@ int32_t IpcServerListener::SendRequest(int32_t cmdCode, std::shared_ptr LOGE("Invalid parameter, pkgName is empty."); return ERR_DM_INPUT_PARA_INVALID; } - sptr listener = IpcServerStub::GetInstance().GetDmListener(processInfo); - if (listener == nullptr) { - LOGE("cannot get listener for package:%{public}s.", processInfo.pkgName.c_str()); - return ERR_DM_POINT_NULL; - } - return listener->SendCmd(cmdCode, req, rsp); + // sptr listener = IpcServerStub::GetInstance().GetDmListener(processInfo); + // if (listener == nullptr) { + // LOGE("cannot get listener for package:%{public}s.", processInfo.pkgName.c_str()); + // return ERR_DM_POINT_NULL; + // } + // return listener->SendCmd(cmdCode, req, rsp); + return 0; } std::vector IpcServerListener::GetAllProcessInfo() diff --git a/services/service/src/ipc/standard/ipc_server_stub.cpp b/services/service/src/ipc/standard/ipc_server_stub.cpp index c85383af7292f05e11704bbdbc510063dd097d6b..663f90dd922b3652a80502810c216a28834bcbb8 100644 --- a/services/service/src/ipc/standard/ipc_server_stub.cpp +++ b/services/service/src/ipc/standard/ipc_server_stub.cpp @@ -282,7 +282,7 @@ ServiceRunningState IpcServerStub::QueryServiceState() const return state_; } -int32_t IpcServerStub::RegisterDeviceManagerListener(const ProcessInfo &processInfo, sptr listener) +int32_t IpcServerStub::RegisterDeviceManagerListener(const ProcessInfo &processInfo, sptr listener) { if (processInfo.pkgName.empty() || listener == nullptr) { LOGE("RegisterDeviceManagerListener error: input parameter invalid."); @@ -321,6 +321,14 @@ int32_t IpcServerStub::RegisterDeviceManagerListener(const ProcessInfo &processI dmListener_[processInfo] = listener; appRecipient_[processInfo] = appRecipient; AddSystemSA(processInfo.pkgName); + // 打印 dmListener_ 的内容和地址 + LOGI("dmListener_ current size: %{public}zu", dmListener_.size()); + for (const auto &entry : dmListener_) { + const ProcessInfo &info = entry.first; + const sptr &broker = entry.second; + LOGI("dmListener_ element - pkgName: %{public}s, userId: %{public}d, listener address: 0x%lx", + info.pkgName.c_str(), info.userId, static_cast(reinterpret_cast(broker.GetRefPtr()))); + } LOGI("complete."); return DM_OK; } @@ -338,6 +346,12 @@ int32_t IpcServerStub::UnRegisterDeviceManagerListener(const ProcessInfo &proces LOGI("Listener not exists"); return DM_OK; } + // 打印当前 dmListener_ 的内容和地址 + LOGI("dmListener_ current size: %{public}zu", dmListener_.size()); + for (const auto &entry : dmListener_) { + LOGI("dmListener_ element - pkgName: %{public}s, userId: %{public}d, listener address: 0x%lx", + entry.first.pkgName.c_str(), entry.first.userId, static_cast(reinterpret_cast(entry.second.GetRefPtr()))); + } auto recipientIter = appRecipient_.find(processInfo); if (recipientIter == appRecipient_.end()) { LOGI("AppRecipient not exists"); @@ -364,13 +378,21 @@ std::vector IpcServerStub::GetAllProcessInfo() { std::vector processInfoVec; std::lock_guard autoLock(listenerLock_); + LOGI("dmListener_ current size: %{public}zu", dmListener_.size()); for (const auto &iter : dmListener_) { - processInfoVec.push_back(iter.first); + const ProcessInfo &info = iter.first; + const sptr &listener = iter.second; + + // 打印元素内容和地址 + LOGI("dmListener_ element - pkgName: %{public}s, userId: %{public}d, listener address: 0x%lx", + info.pkgName.c_str(), info.userId, static_cast(reinterpret_cast(listener.GetRefPtr()))); + + processInfoVec.push_back(info); } return processInfoVec; } -const sptr IpcServerStub::GetDmListener(ProcessInfo processInfo) const +const sptr IpcServerStub::GetDmListener(ProcessInfo processInfo) const { if (processInfo.pkgName.empty()) { LOGE("Invalid parameter, pkgName is empty."); @@ -379,8 +401,13 @@ const sptr IpcServerStub::GetDmListener(ProcessInfo processInfo std::lock_guard autoLock(listenerLock_); auto iter = dmListener_.find(processInfo); if (iter == dmListener_.end()) { + LOGI("dmListener_ does not contain pkgName: %{public}s", processInfo.pkgName.c_str()); return nullptr; } + + // 打印元素内容和地址 + LOGI("dmListener_ element - pkgName: %{public}s, userId: %{public}d, listener address: 0x%lx", + iter->first.pkgName.c_str(), iter->first.userId, static_cast(reinterpret_cast(iter->second.GetRefPtr()))); return iter->second; } diff --git a/test/servicesfuzztest/ipcserverstub_fuzzer/ipc_server_stub_fuzzer.cpp b/test/servicesfuzztest/ipcserverstub_fuzzer/ipc_server_stub_fuzzer.cpp index 1a75d5056d5d3646ec456a6daa445b3059a94823..ec6c23aaf3d48924a4626b44cf2cae2d8d8ad017 100644 --- a/test/servicesfuzztest/ipcserverstub_fuzzer/ipc_server_stub_fuzzer.cpp +++ b/test/servicesfuzztest/ipcserverstub_fuzzer/ipc_server_stub_fuzzer.cpp @@ -53,7 +53,7 @@ void IpcServerStubFuzzTest(const uint8_t* data, size_t size) IpcServerStub::GetInstance().Init(); IpcServerStub::GetInstance().OnRemoteRequest(code, data1, reply, option); - IpcServerStub::GetInstance().RegisterDeviceManagerListener(processInfo, listener); + //IpcServerStub::GetInstance().RegisterDeviceManagerListener(processInfo, listener); IpcServerStub::GetInstance().GetDmListener(processInfo); IpcServerStub::GetInstance().SendCmd(code, req, rsp); IpcServerStub::GetInstance().GetAllProcessInfo(); diff --git a/test/unittest/BUILD.gn b/test/unittest/BUILD.gn index 4901c787a25e7b7b385bad8cfb3cb6578736629d..f25b453c3f7e61214424db602660c9f651106b6e 100644 --- a/test/unittest/BUILD.gn +++ b/test/unittest/BUILD.gn @@ -82,9 +82,6 @@ group("unittest") { ":UTTest_ipc_cmd_parser_service", ":UTTest_ipc_cmd_register", ":UTTest_ipc_get_device_info_rsp", - ":UTTest_ipc_server_client_proxy", - ":UTTest_ipc_server_listener", - ":UTTest_ipc_server_stub", ":UTTest_json_object", ":UTTest_kv_adapter_manager", ":UTTest_mine_hichain_connector",