From 2781d8fa65f72ebe65e2f79b95760797454c8f69 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=A7=A3=E5=BF=97=E6=B5=A9?= Date: Thu, 28 Aug 2025 03:10:54 +0000 Subject: [PATCH] add SetCallingPackageName api MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 解志浩 --- .../inner/ipc/include/bluetooth_host_proxy.h | 1 + .../bluetooth_service_ipc_interface_code.h | 1 + .../inner/ipc/interface/i_bluetooth_host.h | 1 + .../inner/ipc/src/bluetooth_host_proxy.cpp | 19 +++++++++++++++++++ frameworks/inner/src/bluetooth_host.cpp | 9 +++++++++ interfaces/inner_api/include/bluetooth_host.h | 11 +++++++++++ 6 files changed, 42 insertions(+) diff --git a/frameworks/inner/ipc/include/bluetooth_host_proxy.h b/frameworks/inner/ipc/include/bluetooth_host_proxy.h index 5e71b4d6..3c205bde 100644 --- a/frameworks/inner/ipc/include/bluetooth_host_proxy.h +++ b/frameworks/inner/ipc/include/bluetooth_host_proxy.h @@ -123,6 +123,7 @@ public: int32_t GetCarKeyDfxData(std::string &dfxData) override; int32_t SetCarKeyCardData(const std::string &address, int32_t action) override; int32_t NotifyDialogResult(uint32_t dialogType, bool dialogResult) override; + void SetCallingPackageName(const std::string &address, const std::string &packageName) override; private: int32_t InnerTransact(uint32_t code, MessageOption &flags, MessageParcel &data, MessageParcel &reply); static inline BrokerDelegator delegator_; diff --git a/frameworks/inner/ipc/interface/bluetooth_service_ipc_interface_code.h b/frameworks/inner/ipc/interface/bluetooth_service_ipc_interface_code.h index 51975363..ea2ee3f4 100644 --- a/frameworks/inner/ipc/interface/bluetooth_service_ipc_interface_code.h +++ b/frameworks/inner/ipc/interface/bluetooth_service_ipc_interface_code.h @@ -293,6 +293,7 @@ enum BluetoothHostInterfaceCode { BT_GET_CAR_KEY_DFX_DATA, BT_SET_CAR_KEY_CARD_DATA, BT_NOTIFY_DIALOG_RESULT, + BT_SET_CALLING_PACKAGE_NAME, // The last code, if you want to add a new code, please add it before this BT_HOST_BUTT }; diff --git a/frameworks/inner/ipc/interface/i_bluetooth_host.h b/frameworks/inner/ipc/interface/i_bluetooth_host.h index 878b606b..fb54835e 100644 --- a/frameworks/inner/ipc/interface/i_bluetooth_host.h +++ b/frameworks/inner/ipc/interface/i_bluetooth_host.h @@ -150,6 +150,7 @@ public: virtual int32_t GetCarKeyDfxData(std::string &dfxData) = 0; virtual int32_t SetCarKeyCardData(const std::string &address, int32_t action) = 0; virtual int32_t NotifyDialogResult(uint32_t dialogType, bool dialogResult) = 0; + virtual void SetCallingPackageName(const std::string &address, const std::string &packageName) = 0; }; } // namespace Bluetooth } // namespace OHOS diff --git a/frameworks/inner/ipc/src/bluetooth_host_proxy.cpp b/frameworks/inner/ipc/src/bluetooth_host_proxy.cpp index 85ca100d..42643bc1 100644 --- a/frameworks/inner/ipc/src/bluetooth_host_proxy.cpp +++ b/frameworks/inner/ipc/src/bluetooth_host_proxy.cpp @@ -2029,5 +2029,24 @@ int32_t BluetoothHostProxy::NotifyDialogResult(uint32_t dialogType, bool dialogR } return reply.ReadInt32(); } + +void BluetoothHostProxy::SetCallingPackageName(const std::string &address, const std::string &packageName) +{ + MessageParcel data; + if (!data.WriteInterfaceToken(BluetoothHostProxy::GetDescriptor())) { + HILOGE("BluetoothHostProxy::SetCallingPackageName WriteInterfaceToken error"); + return; + } + CHECK_AND_RETURN_LOG(data.WriteString(address), "write address error"); + CHECK_AND_RETURN_LOG(data.WriteString(packageName), "write packageName error"); + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + int32_t error = InnerTransact( + BluetoothHostInterfaceCode::BT_SET_CALLING_PACKAGE_NAME, option, data, reply); + if (error != BT_NO_ERROR) { + HILOGE("BluetoothHostProxy::SetCallingPackageName done fail error: %{public}d", error); + return; + } +} } // namespace Bluetooth } // namespace OHOS diff --git a/frameworks/inner/src/bluetooth_host.cpp b/frameworks/inner/src/bluetooth_host.cpp index ef0f3bf2..3a8d2dc0 100644 --- a/frameworks/inner/src/bluetooth_host.cpp +++ b/frameworks/inner/src/bluetooth_host.cpp @@ -1343,5 +1343,14 @@ int BluetoothHost::NotifyDialogResult(uint32_t dialogType, bool dialogResult) CHECK_AND_RETURN_LOG_RET(proxy != nullptr, BT_ERR_UNAVAILABLE_PROXY, "proxy is nullptr"); return proxy->NotifyDialogResult(dialogType, dialogResult); } + +int32_t BluetoothHost::SetCallingPackageName(const std::string &address, const std::string &packageName) +{ + HILOGI("enter"); + sptr proxy = GetRemoteProxy(BLUETOOTH_HOST); + CHECK_AND_RETURN_LOG_RET(proxy != nullptr, BT_ERR_UNAVAILABLE_PROXY, "proxy is nullptr"); + proxy->SetCallingPackageName(address, packageName); + return BT_NO_ERROR; +} } // namespace Bluetooth } // namespace OHOS diff --git a/interfaces/inner_api/include/bluetooth_host.h b/interfaces/inner_api/include/bluetooth_host.h index 86f82950..7b854d61 100644 --- a/interfaces/inner_api/include/bluetooth_host.h +++ b/interfaces/inner_api/include/bluetooth_host.h @@ -880,6 +880,17 @@ public: * @since 20 */ int NotifyDialogResult(uint32_t dialogType, bool dialogResult); + + /** + * @brief set the package name of calling app which is pairing or connecting remote bluetooth device. + * + * @param address The address of remote bluetooth device. + * @param packageName The package name of calling app. + * @return Returns {@link BT_NO_ERROR} if the operation is successful; + * returns an error code defined in {@link BtErrCode} otherwise. + * @since 21 + */ + int32_t SetCallingPackageName(const std::string &address, const std::string &packageName); private: /** * @brief A constructor used to create a BluetoothHost instance. -- Gitee