From 08202b8e6a99054687bc3e8ebb7c4cc8d3a42530 Mon Sep 17 00:00:00 2001 From: hui Date: Tue, 26 Aug 2025 15:52:09 +0800 Subject: [PATCH] common_event bt Signed-off-by: hui --- .../native/src/common_event_support.cpp | 78 +++++++++++++++++++ interfaces/inner_api/common_event_support.h | 36 +++++++++ interfaces/kits/napi/support/src/support.cpp | 24 ++++++ 3 files changed, 138 insertions(+) diff --git a/frameworks/native/src/common_event_support.cpp b/frameworks/native/src/common_event_support.cpp index bf513bd7..1a64b606 100644 --- a/frameworks/native/src/common_event_support.cpp +++ b/frameworks/native/src/common_event_support.cpp @@ -544,6 +544,13 @@ const std::string CommonEventSupport::COMMON_EVENT_NETMANAGER_NETSTATES_LIMITED const std::string CommonEventSupport::COMMON_EVENT_BLUETOOTH_HANDSFREE_AG_CONNECT_STATE_UPDATE = "usual.event.bluetooth.handsfree.ag.CONNECT_STATE_UPDATE"; +/** + * Indicates the action of a common event that bluetooth handsfree ag connection state change. + * To subscribe to this protected common event, your application must have the ohos.permission.ACCESS_BLUETOOTH + */ +const std::string CommonEventSupport::COMMON_EVENT_BLUETOOTH_HANDSFREE_AG_CONNECT_STATE_CHANGE = + "usual.event.bluetooth.handsfree.ag.CONNECT_STATE_CHANGE"; + /** * Indicates the action of a common event that the device connected to the Bluetooth handsfree is active. * To subscribe to this common event, your application must have the ohos.permission.USE_BLUETOOTH permission. @@ -565,6 +572,13 @@ const std::string CommonEventSupport::COMMON_EVENT_BLUETOOTH_HANDSFREE_AG_AUDIO_ const std::string CommonEventSupport::COMMON_EVENT_BLUETOOTH_A2DPSOURCE_CONNECT_STATE_UPDATE = "usual.event.bluetooth.a2dpsource.CONNECT_STATE_UPDATE"; +/** + * Indicates the action of a common event that bluetooth a2dp source connection state change. + * To subscribe to this protected common event, your application must have the ohos.permission.ACCESS_BLUETOOTH + */ +const std::string CommonEventSupport::COMMON_EVENT_BLUETOOTH_A2DPSOURCE_CONNECT_STATE_CHANGE = + "usual.event.bluetooth.a2dpsource.CONNECT_STATE_CHANGE"; + /** * Indicates the action of a common event that the device connected using Bluetooth A2DP is active. * To subscribe to this common event, your application must have the ohos.permission.USE_BLUETOOTH permission. @@ -585,6 +599,13 @@ const std::string CommonEventSupport::COMMON_EVENT_BLUETOOTH_A2DPSOURCE_PLAYING_ const std::string CommonEventSupport::COMMON_EVENT_BLUETOOTH_A2DPSOURCE_AVRCP_CONNECT_STATE_UPDATE = "usual.event.bluetooth.a2dpsource.AVRCP_CONNECT_STATE_UPDATE"; +/** + * Indicates the action of a common event that bluetooth avrcp connection state change. + * To subscribe to this protected common event, your application must have the ohos.permission.ACCESS_BLUETOOTH + */ +const std::string CommonEventSupport::COMMON_EVENT_BLUETOOTH_A2DPSOURCE_AVRCP_CONNECT_STATE_CHANGE = + "usual.event.bluetooth.a2dpsource.AVRCP_CONNECT_STATE_CHANGE"; + /** * Indicates the action of a common event that the audio codec state of Bluetooth A2DP has changed. * To subscribe to this common event, your application must have the ohos.permission.USE_BLUETOOTH permission. @@ -592,6 +613,13 @@ const std::string CommonEventSupport::COMMON_EVENT_BLUETOOTH_A2DPSOURCE_AVRCP_CO const std::string CommonEventSupport::COMMON_EVENT_BLUETOOTH_A2DPSOURCE_CODEC_VALUE_UPDATE = "usual.event.bluetooth.a2dpsource.CODEC_VALUE_UPDATE"; +/** + * Indicates the action of a common event that bluetooth codec change. + * To subscribe to this protected common event, your application must have the ohos.permission.ACCESS_BLUETOOTH + */ +const std::string CommonEventSupport::COMMON_EVENT_BLUETOOTH_A2DPSOURCE_CODEC_VALUE_CHANGE = + "usual.event.bluetooth.a2dpsource.CODEC_VALUE_CHANGE"; + /** * Indicates the action of a common event that a remote Bluetooth device has been discovered. * To subscribe to this common event, your application must have the ohos.permission.USE_BLUETOOTH and @@ -623,6 +651,13 @@ const std::string CommonEventSupport::COMMON_EVENT_BLUETOOTH_REMOTEDEVICE_ACL_CO const std::string CommonEventSupport::COMMON_EVENT_BLUETOOTH_REMOTEDEVICE_ACL_DISCONNECTED = "usual.event.bluetooth.remotedevice.ACL_DISCONNECTED"; +/** + * Indicates the action of a common event that bluetooth remote device acl state change. + * To subscribe to this protected common event, your application must have the ohos.permission.ACCESS_BLUETOOTH + */ +const std::string CommonEventSupport::COMMON_EVENT_BLUETOOTH_REMOTEDEVICE_ACL_STATE_CHANGE = + "usual.event.bluetooth.remotedevice.ACL_STATE_CHANGE"; + /** * Indicates the action of a common event that the friendly name of a remote Bluetooth device has been retrieved for * the first time or has been changed since the last retrieval. @@ -638,6 +673,13 @@ const std::string CommonEventSupport::COMMON_EVENT_BLUETOOTH_REMOTEDEVICE_NAME_U const std::string CommonEventSupport::COMMON_EVENT_BLUETOOTH_REMOTEDEVICE_PAIR_STATE = "usual.event.bluetooth.remotedevice.PAIR_STATE"; +/** + * Indicates the action of a common event that bluetooth pair state change. + * To subscribe to this protected common event, your application must have the ohos.permission.ACCESS_BLUETOOTH + */ +const std::string CommonEventSupport::COMMON_EVENT_BLUETOOTH_REMOTEDEVICE_PAIR_STATE_CHANGE = + "usual.event.bluetooth.remotedevice.PAIR_STATE_CHANGE"; + /** * Indicates the action of a common event that the battery level of a remote Bluetooth device has been retrieved * for the first time or has been changed since the last retrieval. @@ -2059,6 +2101,12 @@ void CommonEventSupport::Init() */ commonEventSupport_.emplace_back(COMMON_EVENT_BLUETOOTH_HANDSFREE_AG_CONNECT_STATE_UPDATE); + /** + * Indicates the action of a common event that bluetooth handsfree ag connection state change. + * To subscribe to this protected common event, your application must have the ohos.permission.ACCESS_BLUETOOTH + */ + commonEventSupport_.emplace_back(COMMON_EVENT_BLUETOOTH_HANDSFREE_AG_CONNECT_STATE_CHANGE); + /** * Indicates the action of a common event that the device connected to the Bluetooth handsfree is active. * To subscribe to this common event, your application must have the ohos.permission.USE_BLUETOOTH permission. @@ -2077,6 +2125,12 @@ void CommonEventSupport::Init() */ commonEventSupport_.emplace_back(COMMON_EVENT_BLUETOOTH_A2DPSOURCE_CONNECT_STATE_UPDATE); + /** + * Indicates the action of a common event that bluetooth a2dp source connection state change. + * To subscribe to this protected common event, your application must have the ohos.permission.ACCESS_BLUETOOTH + */ + commonEventSupport_.emplace_back(COMMON_EVENT_BLUETOOTH_A2DPSOURCE_CONNECT_STATE_CHANGE); + /** * Indicates the action of a common event that the device connected using Bluetooth A2DP is active. * To subscribe to this common event, your application must have the ohos.permission.USE_BLUETOOTH permission. @@ -2094,12 +2148,24 @@ void CommonEventSupport::Init() */ commonEventSupport_.emplace_back(COMMON_EVENT_BLUETOOTH_A2DPSOURCE_AVRCP_CONNECT_STATE_UPDATE); + /** + * Indicates the action of a common event that bluetooth avrcp connection state change. + * To subscribe to this protected common event, your application must have the ohos.permission.ACCESS_BLUETOOTH + */ + commonEventSupport_.emplace_back(COMMON_EVENT_BLUETOOTH_A2DPSOURCE_AVRCP_CONNECT_STATE_CHANGE); + /** * Indicates the action of a common event that the audio codec state of Bluetooth A2DP has changed. * To subscribe to this common event, your application must have the ohos.permission.USE_BLUETOOTH permission. */ commonEventSupport_.emplace_back(COMMON_EVENT_BLUETOOTH_A2DPSOURCE_CODEC_VALUE_UPDATE); + /** + * Indicates the action of a common event that bluetooth codec change. + * To subscribe to this protected common event, your application must have the ohos.permission.ACCESS_BLUETOOTH + */ + commonEventSupport_.emplace_back(COMMON_EVENT_BLUETOOTH_A2DPSOURCE_CODEC_VALUE_CHANGE); + /** * Indicates the action of a common event that a remote Bluetooth device has been discovered. * To subscribe to this common event, your application must have the ohos.permission.USE_BLUETOOTH and @@ -2127,6 +2193,12 @@ void CommonEventSupport::Init() */ commonEventSupport_.emplace_back(COMMON_EVENT_BLUETOOTH_REMOTEDEVICE_ACL_DISCONNECTED); + /** + * Indicates the action of a common event that bluetooth remote device acl state change. + * To subscribe to this protected common event, your application must have the ohos.permission.ACCESS_BLUETOOTH + */ + commonEventSupport_.emplace_back(COMMON_EVENT_BLUETOOTH_REMOTEDEVICE_ACL_STATE_CHANGE); + /** * Indicates the action of a common event that the friendly name of a remote Bluetooth device has been retrieved for * the first time or has been changed since the last retrieval. @@ -2140,6 +2212,12 @@ void CommonEventSupport::Init() */ commonEventSupport_.emplace_back(COMMON_EVENT_BLUETOOTH_REMOTEDEVICE_PAIR_STATE); + /** + * Indicates the action of a common event that bluetooth pair state change. + * To subscribe to this protected common event, your application must have the ohos.permission.ACCESS_BLUETOOTH + */ + commonEventSupport_.emplace_back(COMMON_EVENT_BLUETOOTH_REMOTEDEVICE_PAIR_STATE_CHANGE); + /** * Indicates the action of a common event that the battery level of a remote Bluetooth device has been retrieved * for the first time or has been changed since the last retrieval. diff --git a/interfaces/inner_api/common_event_support.h b/interfaces/inner_api/common_event_support.h index 5fb0581f..1fa5f481 100644 --- a/interfaces/inner_api/common_event_support.h +++ b/interfaces/inner_api/common_event_support.h @@ -478,6 +478,12 @@ public: */ static const std::string COMMON_EVENT_BLUETOOTH_HANDSFREE_AG_CONNECT_STATE_UPDATE; + /** + * Indicates the action of a common event that bluetooth handsfree ag connection state change. + * To subscribe to this protected common event, your application must have the ohos.permission.ACCESS_BLUETOOTH + */ + static const std::string COMMON_EVENT_BLUETOOTH_HANDSFREE_AG_CONNECT_STATE_CHANGE; + /** * Indicates the action of a common event that the device connected to the Bluetooth handsfree is active. * To subscribe to this common event, your application must have the ohos.permission.USE_BLUETOOTH permission. @@ -496,6 +502,12 @@ public: */ static const std::string COMMON_EVENT_BLUETOOTH_A2DPSOURCE_CONNECT_STATE_UPDATE; + /** + * Indicates the action of a common event that bluetooth a2dp source connection state change. + * To subscribe to this protected common event, your application must have the ohos.permission.ACCESS_BLUETOOTH + */ + static const std::string COMMON_EVENT_BLUETOOTH_A2DPSOURCE_CONNECT_STATE_CHANGE; + /** * Indicates the action of a common event that the device connected using Bluetooth A2DP is active. * To subscribe to this common event, your application must have the ohos.permission.USE_BLUETOOTH permission. @@ -513,12 +525,24 @@ public: */ static const std::string COMMON_EVENT_BLUETOOTH_A2DPSOURCE_AVRCP_CONNECT_STATE_UPDATE; + /** + * Indicates the action of a common event that bluetooth avrcp connection state change. + * To subscribe to this protected common event, your application must have the ohos.permission.ACCESS_BLUETOOTH + */ + static const std::string COMMON_EVENT_BLUETOOTH_A2DPSOURCE_AVRCP_CONNECT_STATE_CHANGE; + /** * Indicates the action of a common event that the audio codec state of Bluetooth A2DP has changed. * To subscribe to this common event, your application must have the ohos.permission.USE_BLUETOOTH permission. */ static const std::string COMMON_EVENT_BLUETOOTH_A2DPSOURCE_CODEC_VALUE_UPDATE; + /** + * Indicates the action of a common event that bluetooth codec change. + * To subscribe to this protected common event, your application must have the ohos.permission.ACCESS_BLUETOOTH + */ + static const std::string COMMON_EVENT_BLUETOOTH_A2DPSOURCE_CODEC_VALUE_CHANGE; + /** * Indicates the action of a common event that a remote Bluetooth device has been discovered. * To subscribe to this common event, your application must have the ohos.permission.USE_BLUETOOTH and @@ -546,6 +570,12 @@ public: */ static const std::string COMMON_EVENT_BLUETOOTH_REMOTEDEVICE_ACL_DISCONNECTED; + /** + * Indicates the action of a common event that bluetooth remote device acl state change. + * To subscribe to this protected common event, your application must have the ohos.permission.ACCESS_BLUETOOTH + */ + static const std::string COMMON_EVENT_BLUETOOTH_REMOTEDEVICE_ACL_STATE_CHANGE; + /** * Indicates the action of a common event that the friendly name of a remote Bluetooth device has been retrieved for * the first time or has been changed since the last retrieval. @@ -559,6 +589,12 @@ public: */ static const std::string COMMON_EVENT_BLUETOOTH_REMOTEDEVICE_PAIR_STATE; + /** + * Indicates the action of a common event that bluetooth pair state change. + * To subscribe to this protected common event, your application must have the ohos.permission.ACCESS_BLUETOOTH + */ + static const std::string COMMON_EVENT_BLUETOOTH_REMOTEDEVICE_PAIR_STATE_CHANGE; + /** * Indicates the action of a common event that the battery level of a remote Bluetooth device has been retrieved * for the first time or has been changed since the last retrieval. diff --git a/interfaces/kits/napi/support/src/support.cpp b/interfaces/kits/napi/support/src/support.cpp index b3bda289..d9db3920 100644 --- a/interfaces/kits/napi/support/src/support.cpp +++ b/interfaces/kits/napi/support/src/support.cpp @@ -208,6 +208,10 @@ napi_value SupportInit(napi_env env, napi_value exports) obj, EventFwk::CommonEventSupport::COMMON_EVENT_BLUETOOTH_HANDSFREE_AG_CONNECT_STATE_UPDATE, "COMMON_EVENT_BLUETOOTH_HANDSFREE_AG_CONNECT_STATE_UPDATE"); + SetNamedPropertyByStr(env, + obj, + EventFwk::CommonEventSupport::COMMON_EVENT_BLUETOOTH_HANDSFREE_AG_CONNECT_STATE_CHANGE, + "COMMON_EVENT_BLUETOOTH_HANDSFREE_AG_CONNECT_STATE_CHANGE"); SetNamedPropertyByStr(env, obj, EventFwk::CommonEventSupport::COMMON_EVENT_BLUETOOTH_HANDSFREE_AG_CURRENT_DEVICE_UPDATE, @@ -220,6 +224,10 @@ napi_value SupportInit(napi_env env, napi_value exports) obj, EventFwk::CommonEventSupport::COMMON_EVENT_BLUETOOTH_A2DPSOURCE_CONNECT_STATE_UPDATE, "COMMON_EVENT_BLUETOOTH_A2DPSOURCE_CONNECT_STATE_UPDATE"); + SetNamedPropertyByStr(env, + obj, + EventFwk::CommonEventSupport::COMMON_EVENT_BLUETOOTH_A2DPSOURCE_CONNECT_STATE_CHANGE, + "COMMON_EVENT_BLUETOOTH_A2DPSOURCE_CONNECT_STATE_CHANGE"); SetNamedPropertyByStr(env, obj, EventFwk::CommonEventSupport::COMMON_EVENT_BLUETOOTH_A2DPSOURCE_CURRENT_DEVICE_UPDATE, @@ -232,10 +240,18 @@ napi_value SupportInit(napi_env env, napi_value exports) obj, EventFwk::CommonEventSupport::COMMON_EVENT_BLUETOOTH_A2DPSOURCE_AVRCP_CONNECT_STATE_UPDATE, "COMMON_EVENT_BLUETOOTH_A2DPSOURCE_AVRCP_CONNECT_STATE_UPDATE"); + SetNamedPropertyByStr(env, + obj, + EventFwk::CommonEventSupport::COMMON_EVENT_BLUETOOTH_A2DPSOURCE_AVRCP_CONNECT_STATE_CHANGE, + "COMMON_EVENT_BLUETOOTH_A2DPSOURCE_AVRCP_CONNECT_STATE_CHANGE"); SetNamedPropertyByStr(env, obj, EventFwk::CommonEventSupport::COMMON_EVENT_BLUETOOTH_A2DPSOURCE_CODEC_VALUE_UPDATE, "COMMON_EVENT_BLUETOOTH_A2DPSOURCE_CODEC_VALUE_UPDATE"); + SetNamedPropertyByStr(env, + obj, + EventFwk::CommonEventSupport::COMMON_EVENT_BLUETOOTH_A2DPSOURCE_CODEC_VALUE_CHANGE, + "COMMON_EVENT_BLUETOOTH_A2DPSOURCE_CODEC_VALUE_CHANGE"); SetNamedPropertyByStr(env, obj, EventFwk::CommonEventSupport::COMMON_EVENT_BLUETOOTH_REMOTEDEVICE_DISCOVERED, @@ -252,6 +268,10 @@ napi_value SupportInit(napi_env env, napi_value exports) obj, EventFwk::CommonEventSupport::COMMON_EVENT_BLUETOOTH_REMOTEDEVICE_ACL_DISCONNECTED, "COMMON_EVENT_BLUETOOTH_REMOTEDEVICE_ACL_DISCONNECTED"); + SetNamedPropertyByStr(env, + obj, + EventFwk::CommonEventSupport::COMMON_EVENT_BLUETOOTH_REMOTEDEVICE_ACL_STATE_CHANGE, + "COMMON_EVENT_BLUETOOTH_REMOTEDEVICE_ACL_STATE_CHANGE"); SetNamedPropertyByStr(env, obj, EventFwk::CommonEventSupport::COMMON_EVENT_BLUETOOTH_REMOTEDEVICE_NAME_UPDATE, @@ -260,6 +280,10 @@ napi_value SupportInit(napi_env env, napi_value exports) obj, EventFwk::CommonEventSupport::COMMON_EVENT_BLUETOOTH_REMOTEDEVICE_PAIR_STATE, "COMMON_EVENT_BLUETOOTH_REMOTEDEVICE_PAIR_STATE"); + SetNamedPropertyByStr(env, + obj, + EventFwk::CommonEventSupport::COMMON_EVENT_BLUETOOTH_REMOTEDEVICE_PAIR_STATE_CHANGE, + "COMMON_EVENT_BLUETOOTH_REMOTEDEVICE_PAIR_STATE_CHANGE"); SetNamedPropertyByStr(env, obj, EventFwk::CommonEventSupport::COMMON_EVENT_BLUETOOTH_REMOTEDEVICE_BATTERY_VALUE_UPDATE, -- Gitee