Skip to content

Commit

Permalink
Add cpu architecture to Windows device info
Browse files Browse the repository at this point in the history
  • Loading branch information
anayw2001 committed Nov 21, 2024
1 parent 2d69758 commit a641c3b
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ class DeviceInfoPlusWindowsPlugin extends DeviceInfoPlatform {

GetSystemInfo(systemInfo);

final cpuArchitecture = deriveCpuArch(systemInfo);

// Use `RtlGetVersion` from `ntdll.dll` to get the Windows version.
RtlGetVersion(osVersionInfo);

Expand Down Expand Up @@ -108,6 +110,7 @@ class DeviceInfoPlusWindowsPlugin extends DeviceInfoPlatform {
registeredOwner: registeredOwner,
releaseId: releaseId,
deviceId: machineId,
cpuArch: cpuArchitecture,
);
return data;
} finally {
Expand All @@ -116,6 +119,25 @@ class DeviceInfoPlusWindowsPlugin extends DeviceInfoPlatform {
}
}

@visibleForTesting
String deriveCpuArch(Pointer<SYSTEM_INFO> systemInfo) {
final cpuArchInt = systemInfo.ref.wProcessorArchitecture;
switch (cpuArchInt) {
case PROCESSOR_ARCHITECTURE.PROCESSOR_ARCHITECTURE_AMD64:
return 'x64';
case PROCESSOR_ARCHITECTURE.PROCESSOR_ARCHITECTURE_ARM:
return 'arm';
case PROCESSOR_ARCHITECTURE.PROCESSOR_ARCHITECTURE_ARM64:
return 'arm64';
case PROCESSOR_ARCHITECTURE.PROCESSOR_ARCHITECTURE_IA64:
return 'ia64';
case PROCESSOR_ARCHITECTURE.PROCESSOR_ARCHITECTURE_INTEL:
return 'x86';
default:
return 'Unknown';
}
}

@visibleForTesting
int getSystemMemoryInMegabytes() {
final memoryInKilobytes = calloc<ULONGLONG>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class WindowsDeviceInfo implements BaseDeviceInfo {
required this.registeredOwner,
required this.releaseId,
required this.deviceId,
required this.cpuArch,
});

/// The computer's fully-qualified DNS name, where available.
Expand Down Expand Up @@ -146,6 +147,9 @@ class WindowsDeviceInfo implements BaseDeviceInfo {
/// `HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\SQMClient\MachineId` registry key.
final String deviceId;

/// Displayed as "System Architecture" in Windows Settings.
final String cpuArch;

@Deprecated('use [data] instead')
@override
Map<String, dynamic> toMap() {
Expand Down Expand Up @@ -175,6 +179,7 @@ class WindowsDeviceInfo implements BaseDeviceInfo {
'registeredOwner': registeredOwner,
'releaseId': releaseId,
'deviceId': deviceId,
'cpuArch': cpuArch,
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,5 +82,7 @@ void main() {
expect(windowsInfo.releaseId, isNotEmpty);
// Check whether windowsInfo.deviceId is a valid non-empty string.
expect(windowsInfo.deviceId, isNotEmpty);
// Check whether windowsInfo.cpuArch is a known variant.
expect(windowsInfo.cpuArch, isNot('Unknown'));
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ void main() {
registeredOwner: 'registeredOwner',
releaseId: 'releaseId',
deviceId: 'deviceId',
cpuArch: 'x64',
);

expect(windowsDeviceInfo.data, {
Expand Down Expand Up @@ -61,6 +62,7 @@ void main() {
'registeredOwner': 'registeredOwner',
'releaseId': 'releaseId',
'deviceId': 'deviceId',
'cpuArch': 'x64',
});
});
});
Expand Down

0 comments on commit a641c3b

Please sign in to comment.