Skip to content

Commit

Permalink
fix: The product name should come from SMBIOS 'Product Name'
Browse files Browse the repository at this point in the history
Unless you are LENOVO or IBM in which case they have forever put their
product names in the 'Version' field instead.

This fixes the default hostname being nonsensical on non-Lenovo systems.

Closes: https://bugs.launchpad.net/bugs/2056167
Closes: canonical/ubuntu-desktop-installer#2394
  • Loading branch information
vanvugt committed Mar 27, 2024
1 parent e238803 commit 56f8724
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions packages/ubuntu_provision/lib/src/identity/identity_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,8 @@ class IdentityModel extends SafeChangeNotifier with PropertyStreamNotifier {
const kDMIProductNameFile = '/sys/devices/virtual/dmi/id/product_name';
@visibleForTesting
const kDMIProductVersionFile = '/sys/devices/virtual/dmi/id/product_version';
@visibleForTesting
const kDMIVendorFile = '/sys/devices/virtual/dmi/id/sys_vendor';

Future<String> _readDmiFile(String path) {
return File(path)
Expand All @@ -211,11 +213,18 @@ Future<String> _readDmiFile(String path) {
}

Future<String> _readProductName() async {
/// Lenovo uses product_version as product name
/// and it's empty on HP and DELL
var productName = await _readDmiFile(kDMIProductVersionFile);
if (productName.isEmpty) {
String productName;
final vendor = await _readDmiFile(kDMIVendorFile);
if (vendor == 'IBM' || vendor == 'LENOVO') {
productName = await _readDmiFile(kDMIProductVersionFile);
if (productName.isEmpty) {
productName = await _readDmiFile(kDMIProductNameFile);
}
} else {
productName = await _readDmiFile(kDMIProductNameFile);
if (productName.isEmpty) {
productName = await _readDmiFile(kDMIProductVersionFile);
}
}
return productName;
}
Expand Down

0 comments on commit 56f8724

Please sign in to comment.