Unverified Commit be9dbfa9 authored by Chris Bracken's avatar Chris Bracken Committed by GitHub

[Linux] Use up_client_get_devices2 when possible (#127699)

The Linux platform channels sample makes a call to the libupower function `up_client_get_devices`, which was deprecated in libupower 0.99.8 in favour of `up_client_get_devices2`.

In order to build both for users on older versions of libupower, such as 0.99.7, which ships with Ubuntu 18.04 (Bionic), as well as users on newer versions where `up_client_get_devices` is deprecated, this adds a preprocessor check and selects the function available on the host system on which the build takes place.

The Flutter devicelab prod bots have been migrated to Ubuntu 20.04 LTS (Focal) which includes 0.99.11, but the trybots are still in the process of being migrated. This allows the build to work on both, and makes life easier for users running on a variety of Linux distributions.

No tests are added or modified since `up_client_get_devices` and `up_client_get_devices2` have the same semantics.

See: https://upower.freedesktop.org/docs/UpClient.html#up-client-get-devices
See: https://gitlab.freedesktop.org/upower/upower/-/blob/master/libupower-glib/up-version.h.in

Note: the `UP_CHECK_VERSION` macro has been around since 2010 (13 years ago), when DKP was forked into libupower. https://gitlab.freedesktop.org/upower/upower/-/commit/27fada20be7feba6783abc5b6cad91ee274ad3df

Issue: https://github.com/flutter/flutter/issues/127611
parent 51d6de18
...@@ -217,12 +217,13 @@ static void my_application_activate(GApplication* application) { ...@@ -217,12 +217,13 @@ static void my_application_activate(GApplication* application) {
G_CALLBACK(up_device_added_cb), self); G_CALLBACK(up_device_added_cb), self);
g_signal_connect_swapped(self->up_client, "device-removed", g_signal_connect_swapped(self->up_client, "device-removed",
G_CALLBACK(up_device_removed_cb), self); G_CALLBACK(up_device_removed_cb), self);
#pragma clang diagnostic push #if UP_CHECK_VERSION(0, 99, 8)
#pragma clang diagnostic ignored "-Wdeprecated-declarations" // up_client_get_devices was deprecated and replaced with
// TODO(cbracken): https://github.com/flutter/flutter/issues/127506 // up_client_get_devices2 in libupower 0.99.8.
// Migrate to up_client_get_devices2 once available. g_autoptr(GPtrArray) devices = up_client_get_devices2(self->up_client);
#else
g_autoptr(GPtrArray) devices = up_client_get_devices(self->up_client); g_autoptr(GPtrArray) devices = up_client_get_devices(self->up_client);
#pragma clang diagnostic pop #endif
for (guint i = 0; i < devices->len; i++) { for (guint i = 0; i < devices->len; i++) {
g_autoptr(UpDevice) device = g_autoptr(UpDevice) device =
static_cast<UpDevice*>(g_ptr_array_index(devices, i)); static_cast<UpDevice*>(g_ptr_array_index(devices, i));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment