2021-08-06 09:42:19

by Yun-hao Chung

[permalink] [raw]
Subject: [PATCH v1 3/3] client: add AffectedByPolicy property

From: Yun-Hao Chung <[email protected]>

This prints property AffectedByPolicy in device info if
org.bluez.AdminPolicyStatus1 exists.

This also rename find_battery_by_path to find_proxies_by_path to reuse
the function.

Reviewed-by: Miao-chen Chou <[email protected]>
---
The following test steps were performed:
1. [bluetooth] menu admin
2. [bluetooth] set-service-allowlist 1124 180A 180F 1812 1801
3. Verify only HID devices are not `Affected by Policy`
4. [bluetooth] set-service-allowlist 1108 110A 110B 110C 110D 110E 110F
1112 111E 111F 1203
5. Verify only audio devices are not `Affected by Policy`
devices are expected.

client/main.c | 20 ++++++++++++++++----
1 file changed, 16 insertions(+), 4 deletions(-)

diff --git a/client/main.c b/client/main.c
index 5297760c8cec..60ccee75a1e5 100644
--- a/client/main.c
+++ b/client/main.c
@@ -56,6 +56,7 @@ static GDBusProxy *default_dev;
static GDBusProxy *default_attr;
static GList *ctrl_list;
static GList *battery_proxies;
+static GList *admin_devices_proxies;

static const char *agent_arguments[] = {
"on",
@@ -542,8 +543,11 @@ static void admin_policy_status_added(GDBusProxy *proxy)

adapter = find_ctrl(ctrl_list, g_dbus_proxy_get_path(proxy));

- if (!adapter)
+ if (!adapter) {
+ admin_devices_proxies = g_list_append(admin_devices_proxies,
+ proxy);
return;
+ }

admin_policy_set_status_proxy(proxy);
}
@@ -654,8 +658,11 @@ static void admin_policy_status_removed(GDBusProxy *proxy)

adapter = find_ctrl(ctrl_list, g_dbus_proxy_get_path(proxy));

- if (!adapter)
+ if (!adapter) {
+ admin_devices_proxies = g_list_remove(admin_devices_proxies,
+ proxy);
return;
+ }

admin_policy_set_status_proxy(NULL);
}
@@ -837,7 +844,7 @@ static struct adapter *find_ctrl_by_address(GList *source, const char *address)
return NULL;
}

-static GDBusProxy *find_battery_by_path(GList *source, const char *path)
+static GDBusProxy *find_proxies_by_path(GList *source, const char *path)
{
GList *list;

@@ -1704,6 +1711,7 @@ static struct GDBusProxy *find_device(int argc, char *argv[])
static void cmd_info(int argc, char *argv[])
{
GDBusProxy *proxy;
+ GDBusProxy *admin_proxy;
GDBusProxy *battery_proxy;
DBusMessageIter iter;
const char *address;
@@ -1747,10 +1755,14 @@ static void cmd_info(int argc, char *argv[])
print_property(proxy, "AdvertisingFlags");
print_property(proxy, "AdvertisingData");

- battery_proxy = find_battery_by_path(battery_proxies,
+ battery_proxy = find_proxies_by_path(battery_proxies,
+ g_dbus_proxy_get_path(proxy));
+ admin_proxy = find_proxies_by_path(admin_devices_proxies,
g_dbus_proxy_get_path(proxy));
print_property_with_label(battery_proxy, "Percentage",
"Battery Percentage");
+ print_property_with_label(admin_proxy, "AffectedByPolicy",
+ "Affected by Policy");

return bt_shell_noninteractive_quit(EXIT_SUCCESS);
}
--
2.32.0.605.g8dce9f2422-goog