From bf37f5d34d4d309533968a87efa517de041a96f9 Mon Sep 17 00:00:00 2001 From: Jonathan Dick Date: Thu, 19 Mar 2020 16:29:30 -0400 Subject: [PATCH 1/3] Cache Android SdkInt at runtime This should never ever change at runtime, so should be safe to cache. --- Xamarin.Essentials/Platform/Platform.android.cs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/Xamarin.Essentials/Platform/Platform.android.cs b/Xamarin.Essentials/Platform/Platform.android.cs index 9a3f06a21..67baf45d9 100644 --- a/Xamarin.Essentials/Platform/Platform.android.cs +++ b/Xamarin.Essentials/Platform/Platform.android.cs @@ -180,8 +180,15 @@ internal static AndroidUri GetShareableFileUri(string filename) false; #endif + static int? sdkInt; + + internal static int SdkInt + => sdkInt.HasValue + ? sdkInt.Value + : (sdkInt = (int)Build.VERSION.SdkInt).Value; + internal static bool HasApiLevel(BuildVersionCodes versionCode) => - (int)Build.VERSION.SdkInt >= (int)versionCode; + SdkInt >= (int)versionCode; internal static CameraManager CameraManager => AppContext.GetSystemService(Context.CameraService) as CameraManager; From fe1febd7e570806a5439ea8041cd7ac0844c397c Mon Sep 17 00:00:00 2001 From: Jonathan Dick Date: Thu, 19 Mar 2020 16:32:34 -0400 Subject: [PATCH 2/3] Nicer syntax --- Xamarin.Essentials/Platform/Platform.android.cs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/Xamarin.Essentials/Platform/Platform.android.cs b/Xamarin.Essentials/Platform/Platform.android.cs index 67baf45d9..2c085d9e6 100644 --- a/Xamarin.Essentials/Platform/Platform.android.cs +++ b/Xamarin.Essentials/Platform/Platform.android.cs @@ -183,9 +183,7 @@ internal static AndroidUri GetShareableFileUri(string filename) static int? sdkInt; internal static int SdkInt - => sdkInt.HasValue - ? sdkInt.Value - : (sdkInt = (int)Build.VERSION.SdkInt).Value; + => sdkInt ?? (sdkInt = (int)Build.VERSION.SdkInt).Value; internal static bool HasApiLevel(BuildVersionCodes versionCode) => SdkInt >= (int)versionCode; From 54c4445fca34b46e225aae90840550f182f4e361 Mon Sep 17 00:00:00 2001 From: James Montemagno Date: Fri, 20 Mar 2020 10:53:03 -0600 Subject: [PATCH 3/3] Update Xamarin.Essentials/Platform/Platform.android.cs Co-Authored-By: Matthew Leibowitz --- Xamarin.Essentials/Platform/Platform.android.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Xamarin.Essentials/Platform/Platform.android.cs b/Xamarin.Essentials/Platform/Platform.android.cs index 2c085d9e6..7a1e830de 100644 --- a/Xamarin.Essentials/Platform/Platform.android.cs +++ b/Xamarin.Essentials/Platform/Platform.android.cs @@ -183,7 +183,7 @@ internal static AndroidUri GetShareableFileUri(string filename) static int? sdkInt; internal static int SdkInt - => sdkInt ?? (sdkInt = (int)Build.VERSION.SdkInt).Value; + => sdkInt ??= (int)Build.VERSION.SdkInt; internal static bool HasApiLevel(BuildVersionCodes versionCode) => SdkInt >= (int)versionCode;