Set trusted profile/device in ACCEPT_ALWAYS authorization case 62/254362/2 accepted/tizen/unified/20210303.130739 submit/tizen/20210303.003641
authorAyush Garg <ayush.garg@samsung.com>
Mon, 1 Mar 2021 13:00:11 +0000 (18:30 +0530)
committerAyush Garg <ayush.garg@samsung.com>
Tue, 2 Mar 2021 07:00:33 +0000 (12:30 +0530)
If ACCEPT_ALWAYS option is selected in authorization popup,
This change will set Profile as trusted if the profile is
PBAP, MAP or SAP. Otherwise it will put device in the
trusted list.
This will allow the user to connect automatically
in future connections without asking for authorization.

Change-Id: I2033f34b8436987d4c4ea87db57c2193cfa7c34c
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
bt-oal/bluez_hal/src/bt-hal-device-dbus-handler.c
bt-oal/bluez_hal/src/bt-hal-device-dbus-handler.h
bt-oal/bluez_hal/src/bt-hal-gap-agent.c
bt-oal/bluez_hal/src/bt-hal-gap-agent.h

index fdf462c8add594763f5c5f235475de7cb1dbcc0d..a42671d4a8b2e6fdf29a1400f18bbbbc5c5592a6 100644 (file)
@@ -488,7 +488,7 @@ int _bt_hal_device_set_trust(const bt_bdaddr_t *bd_addr, uint8_t trust)
                return BT_STATUS_PARM_INVALID;
        }
 
-       DBG("Set authotrize [%d]", authorize);
+       DBG("Set authorize [%d]", authorize);
        result = g_dbus_proxy_call_sync(device_proxy, "Set",
                        g_variant_new("(ssv)", BT_HAL_DEVICE_INTERFACE, "Trusted", g_variant_new("b", authorize)),
                        G_DBUS_CALL_FLAGS_NONE,
@@ -1374,6 +1374,18 @@ static char* __bt_hal_get_trusted_profile_uuid(bt_trusted_profile_t profile)
        return NULL;
 }
 
+bt_trusted_profile_t _bt_hal_get_trusted_profile_enum(const char *uuid)
+{
+       if (g_strcmp0("0000112f-0000-1000-8000-00805f9b34fb", uuid) == 0)
+               return BT_TRUSTED_PROFILE_PBAP;
+       else if (g_strcmp0("00001132-0000-1000-8000-00805f9b34fb", uuid) == 0)
+               return BT_TRUSTED_PROFILE_MAP;
+       else if (g_strcmp0("0000112D-0000-1000-8000-00805f9b34fb", uuid) == 0)
+               return BT_TRUSTED_PROFILE_SAP;
+
+       return 0; /* 0 - Unknown Profile */
+}
+
 int _bt_hal_device_set_trusted_profile(const bt_bdaddr_t *bd_addr,
                bt_trusted_profile_t profile, uint8_t trust)
 {
index 9aaf84ac059e1bf541b57c191ed02a43c2a41393..a986f2caf5d34f7eea7564bc21f801d821f3d547 100644 (file)
@@ -69,6 +69,8 @@ int _bt_hal_device_get_service_connection_state(
 int _bt_hal_device_register_osp_server(uint32_t type, char *uuid, char *path, int fd);
 int _bt_hal_device_unregister_osp_server(uint32_t type, char *uuid);
 
+bt_trusted_profile_t _bt_hal_get_trusted_profile_enum(const char *uuid);
+
 int _bt_hal_device_set_trusted_profile(const bt_bdaddr_t *bd_addr,
                bt_trusted_profile_t profile, uint8_t trust);
 
index 800b735fc55b311792e557060df920ba12b4353b..d6a32a59f6aa46cdf6a7557fe827b0b33cddf2d5 100644 (file)
@@ -41,6 +41,7 @@
 #include <dlog.h>
 
 #include "bt-hal-adapter-dbus-handler.h"
+#include "bt-hal-device-dbus-handler.h"
 #include "bt-hal-dbus-common-utils.h"
 
 static GDBusConnection *connection = NULL;
@@ -727,6 +728,7 @@ static void __bt_gap_agent_method(GDBusConnection *connection,
 
                priv->exec_type = GAP_AGENT_EXEC_AUTHORZATION;
                priv->reply_context = invocation;
+               priv->uuid = g_strdup(uuid);
 
                addr = strstr(path, "dev_");
                if (addr != NULL) {
@@ -1055,7 +1057,25 @@ gboolean gap_agent_reply_authorize(GapAgentPrivate *agent, const guint accept,
                if (accept == GAP_AGENT_ACCEPT) {
                        g_dbus_method_invocation_return_value(priv->reply_context, NULL);
                } else if (accept == GAP_AGENT_ACCEPT_ALWAYS) {
-                       /* TODO: Enable below logic after set authorization API implementation */
+                       bluetooth_device_address_t addr = { { 0, } };
+                       int result;
+                       bt_trusted_profile_t profile;
+
+                       _bt_hal_convert_addr_string_to_type(addr.addr,
+                                                       priv->authorize_addr);
+
+                       profile = _bt_hal_get_trusted_profile_enum(priv->uuid);
+
+                       if (profile)
+                               result = _bt_hal_device_set_trusted_profile((bt_bdaddr_t *)(&addr), profile, TRUE);
+                       else
+                               result = _bt_hal_device_set_trust((bt_bdaddr_t *)(&addr), TRUE);
+
+                       if (result == BT_STATUS_SUCCESS) {
+                               INFO("[%s] Profile added as trusted for Device[%s]",
+                                               priv->uuid, priv->authorize_addr);
+                       }
+
                        g_dbus_method_invocation_return_value(priv->reply_context, NULL);
                } else {
                        switch (accept) {
@@ -1089,6 +1109,10 @@ gboolean gap_agent_reply_authorize(GapAgentPrivate *agent, const guint accept,
        priv->reply_context = NULL;
        memset(priv->authorize_addr, 0x00, sizeof(priv->authorize_addr));
 
+       if (priv->uuid) {
+               g_free(priv->uuid);
+               priv->uuid = NULL;
+       }
        return ret;
 }
 
index 67daab3021b43207ba4386dafd1feb5715790478..9abb61ebc8f45ff666a890d6b77212ec4924aafc 100644 (file)
@@ -86,6 +86,7 @@ struct _GapAgentPrivate {
        GDBusProxy *dbus_proxy;
        GapAgentExecType exec_type;
        GDBusMethodInvocation *reply_context;
+       char *uuid;
 
        char pairing_addr[18];
        char authorize_addr[18];