From b558401b52fa0aa3b59bb3fd9510c60063e1c67b Mon Sep 17 00:00:00 2001 From: Roman Shevchenko Date: Tue, 22 Oct 2024 22:49:56 +0200 Subject: [PATCH] [platform] machine ID detection: minor optimization, one more Linux source (cherry-picked from commit bb954b4da53f85c1f0938bb1dc787ee0eb5ba7bc) IJ-CR-147524 GitOrigin-RevId: 23a8952dbec25061e4d3c3eedf5f100a8d427050 --- .../statistic/eventLog/fus/MachineIdManager.kt | 12 ++++++------ .../internal/statistic/MachineIdManagerTest.kt | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/platform/statistics/src/com/intellij/internal/statistic/eventLog/fus/MachineIdManager.kt b/platform/statistics/src/com/intellij/internal/statistic/eventLog/fus/MachineIdManager.kt index 8b8e644c4526..d0294eb79c04 100644 --- a/platform/statistics/src/com/intellij/internal/statistic/eventLog/fus/MachineIdManager.kt +++ b/platform/statistics/src/com/intellij/internal/statistic/eventLog/fus/MachineIdManager.kt @@ -3,7 +3,7 @@ package com.intellij.internal.statistic.eventLog.fus import com.intellij.internal.statistic.eventLog.EventLogConfiguration import com.intellij.openapi.diagnostic.logger -import com.intellij.openapi.util.SystemInfo +import com.intellij.util.system.OS import com.sun.jna.platform.mac.IOKitUtil import com.sun.jna.platform.win32.Advapi32Util import com.sun.jna.platform.win32.COM.WbemcliUtil @@ -31,10 +31,10 @@ object MachineIdManager { private val machineId: Lazy = lazy { runCatching { - when { - SystemInfo.isWindows -> getWindowsMachineId() - SystemInfo.isMac -> getMacOsMachineId() - SystemInfo.isLinux -> getLinuxMachineId() + when (OS.CURRENT) { + OS.Windows -> getWindowsMachineId() + OS.macOS -> getMacOsMachineId() + OS.Linux -> getLinuxMachineId() else -> null } }.onFailure { LOG.debug(it) }.getOrNull() @@ -67,7 +67,7 @@ object MachineIdManager { /** See [MACHINE-ID(5)](https://manpages.debian.org/testing/systemd/machine-id.5.en.html). */ private fun getLinuxMachineId(): String? = - sequenceOf("/etc/machine-id", "/var/lib/dbus/machine-id") + sequenceOf("/etc/machine-id", "/var/lib/dbus/machine-id", "/sys/devices/virtual/dmi/id/product_uuid") .map { runCatching { Path.of(it).readText().trim().takeIf(String::isNotEmpty) } .onFailure { LOG.debug(it) } diff --git a/platform/statistics/test/com/intellij/internal/statistic/MachineIdManagerTest.kt b/platform/statistics/test/com/intellij/internal/statistic/MachineIdManagerTest.kt index a844415bf576..add536d8618f 100644 --- a/platform/statistics/test/com/intellij/internal/statistic/MachineIdManagerTest.kt +++ b/platform/statistics/test/com/intellij/internal/statistic/MachineIdManagerTest.kt @@ -9,7 +9,7 @@ import org.junit.jupiter.api.Test class MachineIdManagerTest { @Test fun smoke() { assertThat(MachineIdManager.getAnonymizedMachineId("test")) - .isNotNull + .isNotBlank } @Test fun contract() {