Coverage Report

Created: 2025-07-11 06:31

/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
#ifdef HOST_MACHINE_SYSTEM_DARWIN
12
#include "fu-context-private.h"
13
#endif
14
#include "fu-hwids-private.h"
15
16
gboolean
17
fu_hwids_darwin_setup(FuContext *ctx, FuHwids *self, GError **error)
18
0
{
19
#ifdef HOST_MACHINE_SYSTEM_DARWIN
20
  struct {
21
    const gchar *hwid;
22
    const gchar *key;
23
  } map[] = {{FU_HWIDS_KEY_BIOS_VERSION, "System Firmware Version"},
24
       {FU_HWIDS_KEY_FAMILY, "Model Name"},
25
       {FU_HWIDS_KEY_PRODUCT_NAME, "Model Identifier"},
26
       {NULL}};
27
  const gchar *family = NULL;
28
  g_autofree gchar *standard_output = NULL;
29
  g_auto(GStrv) lines = NULL;
30
31
  /* parse the profiler output */
32
  if (!g_spawn_command_line_sync("system_profiler SPHardwareDataType",
33
               &standard_output,
34
               NULL,
35
               NULL,
36
               error))
37
    return FALSE;
38
  lines = g_strsplit(standard_output, "\n", -1);
39
  for (guint j = 0; lines[j] != NULL; j++) {
40
    for (guint i = 0; map[i].key != NULL; i++) {
41
      g_auto(GStrv) chunks = g_strsplit(lines[j], ":", 2);
42
      if (g_strv_length(chunks) != 2)
43
        continue;
44
      if (g_strstr_len(chunks[0], -1, map[i].key) != NULL)
45
        fu_hwids_add_value(self, map[i].hwid, g_strstrip(chunks[1]));
46
    }
47
  }
48
49
  /* this has to be hardcoded */
50
  fu_hwids_add_value(self, FU_HWIDS_KEY_BASEBOARD_MANUFACTURER, "Apple");
51
  fu_hwids_add_value(self, FU_HWIDS_KEY_MANUFACTURER, "Apple");
52
  fu_hwids_add_value(self, FU_HWIDS_KEY_BIOS_VENDOR, "Apple");
53
54
  /* set the chassis kind using the family */
55
  family = fu_hwids_get_value(self, FU_HWIDS_KEY_FAMILY);
56
  if (g_strcmp0(family, "MacBook Pro") == 0) {
57
    fu_hwids_add_value(self, FU_HWIDS_KEY_ENCLOSURE_KIND, "a");
58
    fu_context_set_chassis_kind(ctx, FU_SMBIOS_CHASSIS_KIND_LAPTOP);
59
  }
60
#endif
61
62
  /* success */
63
0
  return TRUE;
64
0
}