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

Commit

Permalink
Cache device type and name (#1087)
Browse files Browse the repository at this point in the history
Co-authored-by: Jonathan Dick <[email protected]>
  • Loading branch information
jamesmontemagno and Redth authored Feb 19, 2020
1 parent 3fe142a commit d73fb42
Showing 1 changed file with 25 additions and 4 deletions.
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;
}
}
}

0 comments on commit d73fb42

Please sign in to comment.