[users] Read product from the device tree on DT platforms

Non-DMI platforms may have a device tree instead (e.g. many embedded
devices, Apple Silicon Macs). If we find a model string in the DT, use
that as a fallback when DMI is not available.

Signed-off-by: Hector Martin <marcan@marcan.st>
This commit is contained in:
Hector Martin 2022-03-18 08:51:42 +09:00
parent f53b064296
commit 17e1027ea2

View File

@ -339,15 +339,30 @@ guessProductName()
if ( !tried )
{
QFile dmiFile( QStringLiteral( "/sys/devices/virtual/dmi/id/product_name" ) );
QFile modelFile( QStringLiteral( "/proc/device-tree/model" ) );
if ( dmiFile.exists() && dmiFile.open( QIODevice::ReadOnly ) )
{
dmiProduct = cleanupForHostname( QString::fromLocal8Bit( dmiFile.readAll().simplified().data() ) );
}
if ( dmiProduct.isEmpty() )
if ( !dmiProduct.isEmpty() )
{
dmiProduct = QStringLiteral( "pc" );
tried = true;
return dmiProduct;
}
}
if ( modelFile.exists() && modelFile.open( QIODevice::ReadOnly ) )
{
dmiProduct
= cleanupForHostname( QString::fromLocal8Bit( modelFile.readAll().chopped( 1 ).simplified().data() ) );
if ( !dmiProduct.isEmpty() )
{
tried = true;
return dmiProduct;
}
}
dmiProduct = QStringLiteral( "pc" );
tried = true;
}
return dmiProduct;