diff --git a/frameworks/inner/ipc/include/bluetooth_host_proxy.h b/frameworks/inner/ipc/include/bluetooth_host_proxy.h index 5e71b4d6f25f18efc4c507534ba2f355f08b43a9..3c205bded9c322a745b81969c7a2a26b70b57937 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 51975363328577f8126a53be3fa3cba0554984ee..ea2ee3f47f04c5e79f7718b84fc11f1674ca451c 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 878b606bc40e714821d10b0cfc8578e82a06a540..fb54835eca0c83242cf0574d8969a9f410de61b2 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 85ca100db1417a85b1f200eca26142a6e264dbba..42643bc1e1d637d63b624c75baa22f6b9571f09f 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 ef0f3bf2fe1d30fe8fedb5f1940b7fd5f5c44eb9..3a8d2dc0ceb717ea088ebc26980b65c7abeabec5 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 86f829503cb1002918d87aa9343900dfbdc8666e..7b854d61a0b58e158a57892914454239e9853d6e 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.