From 06c1cc52ab261fbd4939daf4337867564085cf24 Mon Sep 17 00:00:00 2001 From: Vibhav Pant Date: Fri, 1 Sep 2023 20:01:13 +0530 Subject: [PATCH] Minor refactor. --- internal/platform/implementation/linux/device_info.cc | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/internal/platform/implementation/linux/device_info.cc b/internal/platform/implementation/linux/device_info.cc index 0d431426..c91a4956 100644 --- a/internal/platform/implementation/linux/device_info.cc +++ b/internal/platform/implementation/linux/device_info.cc @@ -79,14 +79,12 @@ api::DeviceInfo::DeviceType DeviceInfo::GetDeviceType() const { try { std::string chasis = hostnamed.Chassis(); api::DeviceInfo::DeviceType device = api::DeviceInfo::DeviceType::kUnknown; - if (chasis == "phone") { + if (chasis == "phone" || chasis == "handset") { device = api::DeviceInfo::DeviceType::kPhone; } else if (chasis == "laptop" || chasis == "desktop") { device = api::DeviceInfo::DeviceType::kLaptop; } else if (chasis == "tablet") { device = api::DeviceInfo::DeviceType::kTablet; - } else if (chasis == "handset") { - device = api::DeviceInfo::DeviceType::kPhone; } return device; } catch (const sdbus::Error &e) { @@ -97,20 +95,20 @@ api::DeviceInfo::DeviceType DeviceInfo::GetDeviceType() const { std::optional DeviceInfo::GetFullName() const { struct passwd *pwd = getpwuid(getuid()); - if (!pwd) { + if (pwd == nullptr) { return std::nullopt; } char *name = strtok(pwd->pw_gecos, ","); std::wstring_convert, char16_t> convert; - return convert.from_bytes(name ? name : pwd->pw_gecos); + return convert.from_bytes(name == nullptr ? name : pwd->pw_gecos); } std::optional DeviceInfo::GetProfileUserName() const { struct passwd *pwd = getpwuid(getuid()); if (pwd == nullptr) { return std::nullopt; - } + } char *name = strtok(pwd->pw_gecos, ","); return std::string(name); }