/src/fwupd/libfwupdplugin/fu-hwids-darwin.c
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * Copyright 2021 Richard Hughes <richard@hughsie.com> |
3 | | * |
4 | | * SPDX-License-Identifier: LGPL-2.1-or-later |
5 | | */ |
6 | | |
7 | | #define G_LOG_DOMAIN "FuContext" |
8 | | |
9 | | #include "config.h" |
10 | | |
11 | | #include "fu-context-private.h" |
12 | | #include "fu-hwids-private.h" |
13 | | |
14 | | gboolean |
15 | | fu_hwids_darwin_setup(FuContext *ctx, FuHwids *self, GError **error) |
16 | 0 | { |
17 | | #ifdef HOST_MACHINE_SYSTEM_DARWIN |
18 | | struct { |
19 | | const gchar *hwid; |
20 | | const gchar *key; |
21 | | } map[] = {{FU_HWIDS_KEY_BIOS_VERSION, "System Firmware Version"}, |
22 | | {FU_HWIDS_KEY_FAMILY, "Model Name"}, |
23 | | {FU_HWIDS_KEY_PRODUCT_NAME, "Model Identifier"}, |
24 | | {NULL}}; |
25 | | const gchar *family = NULL; |
26 | | g_autofree gchar *standard_output = NULL; |
27 | | g_auto(GStrv) lines = NULL; |
28 | | |
29 | | /* parse the profiler output */ |
30 | | if (!g_spawn_command_line_sync("system_profiler SPHardwareDataType", |
31 | | &standard_output, |
32 | | NULL, |
33 | | NULL, |
34 | | error)) |
35 | | return FALSE; |
36 | | lines = g_strsplit(standard_output, "\n", -1); |
37 | | for (guint j = 0; lines[j] != NULL; j++) { |
38 | | for (guint i = 0; map[i].key != NULL; i++) { |
39 | | g_auto(GStrv) chunks = g_strsplit(lines[j], ":", 2); |
40 | | if (g_strv_length(chunks) != 2) |
41 | | continue; |
42 | | if (g_strstr_len(chunks[0], -1, map[i].key) != NULL) |
43 | | fu_hwids_add_value(self, map[i].hwid, g_strstrip(chunks[1])); |
44 | | } |
45 | | } |
46 | | |
47 | | /* this has to be hardcoded */ |
48 | | fu_hwids_add_value(self, FU_HWIDS_KEY_BASEBOARD_MANUFACTURER, "Apple"); |
49 | | fu_hwids_add_value(self, FU_HWIDS_KEY_MANUFACTURER, "Apple"); |
50 | | fu_hwids_add_value(self, FU_HWIDS_KEY_BIOS_VENDOR, "Apple"); |
51 | | |
52 | | /* set the chassis kind using the family */ |
53 | | family = fu_hwids_get_value(self, FU_HWIDS_KEY_FAMILY); |
54 | | if (g_strcmp0(family, "MacBook Pro") == 0) { |
55 | | fu_hwids_add_value(self, FU_HWIDS_KEY_ENCLOSURE_KIND, "a"); |
56 | | fu_context_set_chassis_kind(ctx, FU_SMBIOS_CHASSIS_KIND_LAPTOP); |
57 | | } |
58 | | #endif |
59 | | |
60 | | /* success */ |
61 | 0 | return TRUE; |
62 | 0 | } |