linux: up-device-supply: Update the model name after changing the device type

The model name of a device component may be different. For example,
Dualshock joystick owns "Sony Interactive Entertainment DualSense
Wireless Controller" for the joystick and "Sony Interactive
Entertainment DualSense Wireless Controller Motion Sensors" for the
accelerometer. If the device type is changed based on the device
priority, the corresponding model name have to be changed.

Resolves: #295

Tested-by: Mateus Rodrigues Costa <mateusrodcosta@gmail.com>
Signed-off-by: Kate Hsuan <hpa@redhat.com>
This commit is contained in:
Kate Hsuan 2025-01-14 13:18:15 +08:00
parent 351affe12f
commit f17d3bfcd0

View file

@ -333,6 +333,7 @@ up_device_supply_sibling_discovered_guess_type (UpDevice *device,
{
GUdevDevice *input;
UpDeviceKind cur_type, new_type;
const gchar *new_model_name = NULL;
char *model_name;
char *serial_number;
int i;
@ -468,7 +469,19 @@ up_device_supply_sibling_discovered_guess_type (UpDevice *device,
g_debug ("Type changed from %s to %s",
up_device_kind_to_string(cur_type),
up_device_kind_to_string(new_type));
g_object_set (device, "type", new_type, NULL);
new_model_name = g_udev_device_get_sysfs_attr (input, "name");
/* The model name of a device component may be different. For example, DualSense
* joystick owns "Sony Interactive Entertainment DualSense Wireless Controller"
* for the joystick and "Sony Interactive Entertainment DualSense Wireless Controller
* Motion Sensors" for the accelerometer. If the type is change, the corresponding
* model name have to be changed too. */
if (new_model_name != NULL)
g_object_set (device,
"type", new_type,
"model", new_model_name,
NULL);
else
g_object_set (device, "type", new_type, NULL);
}
}