Skip to content

Commit

Permalink
Expose OS Version
Browse files Browse the repository at this point in the history
  • Loading branch information
m-sadegh-sh committed Mar 10, 2024
1 parent 914b763 commit 52a3905
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 5 deletions.
23 changes: 21 additions & 2 deletions Core/Device/OS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ public static partial class OS
public static readonly DevicePlatform Platform = DevicePlatform.Windows;
#endif

static string hardwareModel;

public static async Task<bool> OpenBrowser(string url, OnError errorAction = OnError.Toast)
{
try
Expand All @@ -42,6 +40,7 @@ public static async Task<bool> OpenSettings(string section = null, OnError error
}
}

static string hardwareModel;
public static string HardwareModel
{
get
Expand All @@ -60,5 +59,25 @@ public static string HardwareModel
}
}
}

static string version;
public static string Version
{
get
{
if (version.HasValue()) return version;

try
{
version = DetectOSVersion();
return version.Or("UNKNOWN");
}
catch (Exception ex)
{
Log.For(typeof(OS)).Error(ex, "Failed to detect device model.");
return "UNKNOWN";
}
}
}
}
}
7 changes: 7 additions & 0 deletions Zebble/Android/Device/OS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ namespace Zebble.Device
using Android.Content;
using Android.OS;
using AndroidOS;
#if XAMARIN
using Xamarin.Essentials;
#else
using Microsoft.Maui.Devices;
#endif
using Olive;

partial class OS
Expand Down Expand Up @@ -79,6 +84,8 @@ static string DetectHardwareModel()

return new[] { manufacturer?.ToProperCase(), model?.ToProperCase() }.Trim().ToString(" ");
}

static string DetectOSVersion() => DeviceInfo.VersionString;

public static bool IsAtLeast(BuildVersionCodes version) => Build.VERSION.SdkInt >= version;

Expand Down
12 changes: 12 additions & 0 deletions Zebble/Windows/Device/OS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ namespace Zebble.Device
using System.Threading.Tasks;
using Windows.Security.ExchangeActiveSyncProvisioning;
using Olive;
using Windows.System.Profile;

partial class OS
{
Expand Down Expand Up @@ -31,5 +32,16 @@ static string DetectHardwareModel()
var eas = new EasClientDeviceInformation();
return new[] { eas.SystemManufacturer, eas.SystemProductName }.Trim().ToString(" ");
}

static string DetectOSVersion()
{
string sv = AnalyticsInfo.VersionInfo.DeviceFamilyVersion;
ulong v = ulong.Parse(sv);
ulong v1 = (v & 0xFFFF000000000000L) >> 48;
ulong v2 = (v & 0x0000FFFF00000000L) >> 32;
ulong v3 = (v & 0x00000000FFFF0000L) >> 16;
ulong v4 = (v & 0x000000000000FFFFL);
return $"{v1}.{v2}.{v3}.{v4}";
}
}
}
4 changes: 2 additions & 2 deletions Zebble/Zebble.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
<RootNamespace>Zebble</RootNamespace>
<PackageId>Zebble</PackageId>
<Product>$(AssemblyName) ($(TargetFramework))</Product>
<Version>5.0.4.0</Version>
<Version>5.0.5.0</Version>
<PackOnBuild>true</PackOnBuild>
<UseMaui>true</UseMaui>
<UseMaui>true</UseMaui>
<SingleProject>true</SingleProject>
<NeutralLanguage>en</NeutralLanguage>
<NoWarn>0618;0162</NoWarn>
Expand Down
9 changes: 8 additions & 1 deletion Zebble/iOS/Device/OS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ namespace Zebble.Device
using System.Threading.Tasks;
using UIKit;
using Olive;
#if XAMARIN
using Xamarin.Essentials;
#else
using Microsoft.Maui.Devices;
#endif

partial class OS
{
Expand Down Expand Up @@ -343,8 +348,10 @@ static string DetectHardwareModel()

if (hardware == "i386" || hardware == "x86_64") return "Simulator";

return hardware == "" ? "Unknown" : hardware;
return hardware.Or("Unknown");
}

static string DetectOSVersion() => DeviceInfo.VersionString;
#endregion
}
}

0 comments on commit 52a3905

Please sign in to comment.