From 52a3905d4ee3c54a477d06d0617a2533dcada6b6 Mon Sep 17 00:00:00 2001 From: Mohammad Sadegh Shad Date: Sun, 10 Mar 2024 14:12:12 +0330 Subject: [PATCH] Expose OS Version --- Core/Device/OS.cs | 23 +++++++++++++++++++++-- Zebble/Android/Device/OS.cs | 7 +++++++ Zebble/Windows/Device/OS.cs | 12 ++++++++++++ Zebble/Zebble.csproj | 4 ++-- Zebble/iOS/Device/OS.cs | 9 ++++++++- 5 files changed, 50 insertions(+), 5 deletions(-) diff --git a/Core/Device/OS.cs b/Core/Device/OS.cs index 9133977..7378470 100644 --- a/Core/Device/OS.cs +++ b/Core/Device/OS.cs @@ -14,8 +14,6 @@ public static partial class OS public static readonly DevicePlatform Platform = DevicePlatform.Windows; #endif - static string hardwareModel; - public static async Task OpenBrowser(string url, OnError errorAction = OnError.Toast) { try @@ -42,6 +40,7 @@ public static async Task OpenSettings(string section = null, OnError error } } + static string hardwareModel; public static string HardwareModel { get @@ -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"; + } + } + } } } \ No newline at end of file diff --git a/Zebble/Android/Device/OS.cs b/Zebble/Android/Device/OS.cs index 035d2a1..e816fd3 100644 --- a/Zebble/Android/Device/OS.cs +++ b/Zebble/Android/Device/OS.cs @@ -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 @@ -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; diff --git a/Zebble/Windows/Device/OS.cs b/Zebble/Windows/Device/OS.cs index 8398473..3556007 100644 --- a/Zebble/Windows/Device/OS.cs +++ b/Zebble/Windows/Device/OS.cs @@ -4,6 +4,7 @@ namespace Zebble.Device using System.Threading.Tasks; using Windows.Security.ExchangeActiveSyncProvisioning; using Olive; + using Windows.System.Profile; partial class OS { @@ -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}"; + } } } \ No newline at end of file diff --git a/Zebble/Zebble.csproj b/Zebble/Zebble.csproj index 0954fde..9e4c264 100644 --- a/Zebble/Zebble.csproj +++ b/Zebble/Zebble.csproj @@ -7,9 +7,9 @@ Zebble Zebble $(AssemblyName) ($(TargetFramework)) - 5.0.4.0 + 5.0.5.0 true - true + true true en 0618;0162 diff --git a/Zebble/iOS/Device/OS.cs b/Zebble/iOS/Device/OS.cs index a841751..dda2560 100644 --- a/Zebble/iOS/Device/OS.cs +++ b/Zebble/iOS/Device/OS.cs @@ -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 { @@ -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 } } \ No newline at end of file