From 40d76be530fa90552d98b12509ae533e4763915f Mon Sep 17 00:00:00 2001 From: Bruin06 <419738327@qq.com> Date: Fri, 12 Sep 2025 10:31:52 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E6=8E=A5=E5=8F=A3IsFirstConn?= =?UTF-8?q?ectedAfterPaired?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Bruin06 <419738327@qq.com> --- .../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 | 25 +++++++++++++++++++ .../inner/src/bluetooth_remote_device.cpp | 9 +++++++ .../include/bluetooth_remote_device.h | 9 +++++++ 6 files changed, 46 insertions(+) diff --git a/frameworks/inner/ipc/include/bluetooth_host_proxy.h b/frameworks/inner/ipc/include/bluetooth_host_proxy.h index 60c22240..bac0d533 100644 --- a/frameworks/inner/ipc/include/bluetooth_host_proxy.h +++ b/frameworks/inner/ipc/include/bluetooth_host_proxy.h @@ -125,6 +125,7 @@ public: 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; + bool IsFirstConnectedAfterPaired(int32_t transport, const std::string &address) 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 f99b531c..0b259e02 100644 --- a/frameworks/inner/ipc/interface/bluetooth_service_ipc_interface_code.h +++ b/frameworks/inner/ipc/interface/bluetooth_service_ipc_interface_code.h @@ -296,6 +296,7 @@ enum BluetoothHostInterfaceCode { BT_NOTIFY_DIALOG_RESULT, BT_SET_CALLING_PACKAGE_NAME, BT_GET_CONNECTED_BLE_DEVICES, + IS_FIRST_CONNECT_AFTER_BOND, // 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 c6c059c9..89c5f62d 100644 --- a/frameworks/inner/ipc/interface/i_bluetooth_host.h +++ b/frameworks/inner/ipc/interface/i_bluetooth_host.h @@ -152,6 +152,7 @@ public: 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; + virtual bool IsFirstConnectedAfterPaired(int32_t transport, const std::string &address) = 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 1cd43299..3f6477cf 100644 --- a/frameworks/inner/ipc/src/bluetooth_host_proxy.cpp +++ b/frameworks/inner/ipc/src/bluetooth_host_proxy.cpp @@ -2093,5 +2093,30 @@ void BluetoothHostProxy::SetCallingPackageName(const std::string &address, const return; } } + +bool BluetoothHostProxy::IsFirstConnectedAfterPaired(int32_t transport, const std::string &address) +{ + MessageParcel data; + if (!data.WriteInterfaceToken(BluetoothHostProxy::GetDescriptor())) { + HILOGE("BluetoothHostProxy::IsFirstConnectedAfterPaired WriteInterfaceToken error"); + return false; + } + if (!data.WriteInt32(transport)) { + HILOGE("BluetoothHostProxy::IsFirstConnectedAfterPaired transport error"); + return false; + } + if (!data.WriteString(address)) { + HILOGE("BluetoothHostProxy::IsFirstConnectedAfterPaired address error"); + return false; + } + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + int32_t error = InnerTransact(BluetoothHostInterfaceCode::IS_FIRST_CONNECT_AFTER_BOND, option, data, reply); + if (error != NO_ERROR) { + HILOGE("BluetoothHostProxy::IsFirstConnectedAfterPaired done fail, error: %{public}d", error); + return false; + } + return reply.ReadBool(); +} } // namespace Bluetooth } // namespace OHOS diff --git a/frameworks/inner/src/bluetooth_remote_device.cpp b/frameworks/inner/src/bluetooth_remote_device.cpp index ddb9e612..864cd0bc 100644 --- a/frameworks/inner/src/bluetooth_remote_device.cpp +++ b/frameworks/inner/src/bluetooth_remote_device.cpp @@ -473,5 +473,14 @@ int32_t BluetoothRemoteDevice::GetDeviceTransport(int32_t &transport) const CHECK_AND_RETURN_LOG_RET(hostProxy != nullptr, BT_ERR_INTERNAL_ERROR, "proxy is nullptr"); return hostProxy->GetDeviceTransport(address_, transport); } + +bool BluetoothRemoteDevice::IsFirstConnectedAfterPaired() const +{ + HILOGI("enter"); + CHECK_AND_RETURN_LOG_RET(IsValidBluetoothRemoteDevice(), false, "Invalid remote device"); + sptr hostProxy = GetRemoteProxy(BLUETOOTH_HOST); + CHECK_AND_RETURN_LOG_RET(hostProxy != nullptr, false, "proxy is nullptr."); + return hostProxy->IsFirstConnectedAfterPaired(transport_, address_); +} } // namespace Bluetooth } // namespace OHOS diff --git a/interfaces/inner_api/include/bluetooth_remote_device.h b/interfaces/inner_api/include/bluetooth_remote_device.h index 8b3bda1d..f26cfd99 100644 --- a/interfaces/inner_api/include/bluetooth_remote_device.h +++ b/interfaces/inner_api/include/bluetooth_remote_device.h @@ -432,6 +432,15 @@ public: * @since 20 */ int32_t GetDeviceTransport(int32_t &transport) const; + + /** + * @brief Check if device was first connected after pair, when device is connected. + * + * @return Returns true if device was first connect after pair; + * returns false if device was not first connect after pair. + * @since 6 + */ + bool IsFirstConnectedAfterPaired() const; private: std::string address_ = "00:00:00:00:00:00"; int transport_ = BT_TRANSPORT_NONE; -- Gitee