mirror of
https://git.kernel.org/pub/scm/bluetooth/bluez.git
synced 2025-01-19 10:05:09 +08:00
Fix Device.SetProperty("Trusted",... always emit PropertyChanged
Currently any change done to Trusted property generates a PropertyChanged since no verification is done prior to apply the new value which may generate an unnecessary write to the storage and extra D-Bus traffic. To fix this trusted is now loaded from storage and cached in memory when the device is created, which latter is used to make sure the value has really changed avoiding storage reads to check current value.
This commit is contained in:
parent
fa35778e2f
commit
6da6e4e3de
@ -2980,7 +2980,6 @@ static int btd_adapter_authorize(struct btd_adapter *adapter,
|
||||
struct btd_device *device;
|
||||
struct agent *agent;
|
||||
char address[18];
|
||||
gboolean trusted;
|
||||
const gchar *dev_path;
|
||||
int err;
|
||||
|
||||
@ -3005,9 +3004,7 @@ static int btd_adapter_authorize(struct btd_adapter *adapter,
|
||||
auth->device = device;
|
||||
auth->adapter = adapter;
|
||||
|
||||
trusted = read_trust(&adapter->bdaddr, address, GLOBAL_TRUST);
|
||||
|
||||
if (trusted) {
|
||||
if (device_is_trusted(device) == TRUE) {
|
||||
adapter->auth_idle_id = g_idle_add_full(G_PRIORITY_DEFAULT_IDLE,
|
||||
auth_idle_cb, auth,
|
||||
g_free);
|
||||
|
23
src/device.c
23
src/device.c
@ -134,6 +134,7 @@ struct btd_device {
|
||||
|
||||
sdp_list_t *tmp_records;
|
||||
|
||||
gboolean trusted;
|
||||
gboolean paired;
|
||||
gboolean renewed_key;
|
||||
|
||||
@ -256,6 +257,11 @@ gboolean device_is_paired(struct btd_device *device)
|
||||
return device->paired;
|
||||
}
|
||||
|
||||
gboolean device_is_trusted(struct btd_device *device)
|
||||
{
|
||||
return device->trusted;
|
||||
}
|
||||
|
||||
static DBusMessage *get_properties(DBusConnection *conn,
|
||||
DBusMessage *msg, void *user_data)
|
||||
{
|
||||
@ -326,7 +332,7 @@ static DBusMessage *get_properties(DBusConnection *conn,
|
||||
dict_append_entry(&dict, "Paired", DBUS_TYPE_BOOLEAN, &boolean);
|
||||
|
||||
/* Trusted */
|
||||
boolean = read_trust(&src, dstaddr, GLOBAL_TRUST);
|
||||
boolean = device_is_trusted(device);
|
||||
dict_append_entry(&dict, "Trusted", DBUS_TYPE_BOOLEAN, &boolean);
|
||||
|
||||
/* Connected */
|
||||
@ -379,18 +385,28 @@ static DBusMessage *set_alias(DBusConnection *conn, DBusMessage *msg,
|
||||
}
|
||||
|
||||
static DBusMessage *set_trust(DBusConnection *conn, DBusMessage *msg,
|
||||
dbus_bool_t value, void *data)
|
||||
gboolean value, void *data)
|
||||
{
|
||||
struct btd_device *device = data;
|
||||
struct btd_adapter *adapter = device->adapter;
|
||||
char srcaddr[18], dstaddr[18];
|
||||
bdaddr_t src;
|
||||
int err;
|
||||
|
||||
if (device->trusted == value)
|
||||
return dbus_message_new_method_return(msg);
|
||||
|
||||
adapter_get_address(adapter, &src);
|
||||
ba2str(&src, srcaddr);
|
||||
ba2str(&device->bdaddr, dstaddr);
|
||||
|
||||
write_trust(srcaddr, dstaddr, GLOBAL_TRUST, value);
|
||||
err = write_trust(srcaddr, dstaddr, GLOBAL_TRUST, value);
|
||||
if (err < 0)
|
||||
return g_dbus_create_error(msg,
|
||||
ERROR_INTERFACE ".Failed",
|
||||
strerror(-err));
|
||||
|
||||
device->trusted = value;
|
||||
|
||||
emit_property_changed(conn, dbus_message_get_path(msg),
|
||||
DEVICE_INTERFACE, "Trusted",
|
||||
@ -869,6 +885,7 @@ struct btd_device *device_create(DBusConnection *conn,
|
||||
adapter_get_address(adapter, &src);
|
||||
ba2str(&src, srcaddr);
|
||||
read_device_name(srcaddr, address, device->name);
|
||||
device->trusted = read_trust(&src, address, GLOBAL_TRUST);
|
||||
|
||||
device->auth = 0xff;
|
||||
|
||||
|
@ -54,6 +54,7 @@ void device_set_agent(struct btd_device *device, struct agent *agent);
|
||||
gboolean device_is_busy(struct btd_device *device);
|
||||
gboolean device_is_temporary(struct btd_device *device);
|
||||
gboolean device_is_paired(struct btd_device *device);
|
||||
gboolean device_is_trusted(struct btd_device *device);
|
||||
void device_set_paired(struct btd_device *device, gboolean paired);
|
||||
void device_set_temporary(struct btd_device *device, gboolean temporary);
|
||||
void device_set_cap(struct btd_device *device, uint8_t cap);
|
||||
|
Loading…
Reference in New Issue
Block a user