diff --git a/frameworks/inner/ipc/include/bluetooth_host_proxy.h b/frameworks/inner/ipc/include/bluetooth_host_proxy.h index 60c22240624a34c17c5e760d8da01bfadc15b8f1..bac0d533aa00b3a458f6a0021b8b35431b7985f1 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 f99b531cf6a1d1ce3b80fb7fb734f47343e1854a..0b259e026541f88a3dd98346281129ea69343748 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 c6c059c95149daf357579097b505192989a63be0..89c5f62df6d54e6d80528d2fd5236ba8aae68747 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 1cd43299754c43e6335ae5c9ce958a9b5030b1cb..3f6477cfe51c7da9d61cfedebccc1e5412dc9494 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 ddb9e6122dcf09566994bd5519b50497411c124c..864cd0bc7700e7e9606dadea106a944ba00190c0 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 8b3bda1d68ee90b54db02c9f6bbc4498809a595f..f26cfd99068665e8186c3faeb7343cc284577333 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;