Skip to content
This repository has been archived by the owner on May 15, 2024. It is now read-only.

GH-1014 Try to cache device type on UWP #1087

Merged
merged 3 commits into from
Feb 19, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 25 additions & 4 deletions Xamarin.Essentials/DeviceInfo/DeviceInfo.uwp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,21 @@ public static partial class DeviceInfo
{
static readonly EasClientDeviceInformation deviceInfo;
static DeviceIdiom currentIdiom;
static DeviceType currentType = DeviceType.Unknown;
static string systemProductName;

static DeviceInfo()
{
deviceInfo = new EasClientDeviceInformation();
currentIdiom = DeviceIdiom.Unknown;
try
{
systemProductName = deviceInfo.SystemProductName;
}
catch (Exception ex)
{
Debug.WriteLine($"Unable to get system product name. {ex.Message}");
}
}

static string GetModel() => deviceInfo.SystemProductName;
Expand Down Expand Up @@ -77,12 +87,23 @@ static DeviceIdiom GetIdiom()

static DeviceType GetDeviceType()
{
var isVirtual = deviceInfo.SystemProductName.Contains("Virtual") || deviceInfo.SystemProductName == "HMV domU";
if (currentType != DeviceType.Unknown)
return currentType;

if (isVirtual)
return DeviceType.Virtual;
try
{
if (string.IsNullOrWhiteSpace(systemProductName))
systemProductName = deviceInfo.SystemProductName;

return DeviceType.Physical;
var isVirtual = systemProductName.Contains("Virtual") || systemProductName == "HMV domU";

currentType = isVirtual ? DeviceType.Virtual : DeviceType.Physical;
}
catch (Exception ex)
{
Debug.WriteLine($"Unable to get device type. {ex.Message}");
}
return currentType;
}
}
}