Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check the Windows 10 OS version in an UWP app so as to eliminate WACK test fail?

I am working on an UWP app that uses some features that aren't available in older versions of Windows 10. Therefore, I need to check if Creators Update is installed.

There is version-checking code in the app using AnalyticsInfo.VersionInfo. However, the latest round of WACK tests gave the following Fail:

FAILED Platform version launch • Error Found: The high OS version validation detected the following errors:

o Failed to stop the app AppName.group.mbb.

o The app Company.AppName_2.3.56045.0_x64__cx08jceyq9bcp failed platform version launch test.

• Impact if not fixed: The app should not use version information to provide functionality that is specific to the OS.

• How to fix: Please use recommended methods to check for available functionality in the OS. See the link below for more information. Operating System Version

I am aware of this question, but would rather fix the Fail if possible. I found advice on MSDN about how to make a UWP app "version adaptive" here.

I now have this code:

using Windows.Foundation.Metadata;

if (ApiInformation.IsMethodPresent("Windows.Networking.Connectivity.ConnectionProfile", "GetNetworkUsageAsync"))
    {
        //do stuff
    }

My Windows version is 1703 15063.483, and GetNetworkUsageAsync is used successfully elsewhere in the code. But the call to IsMethodPresent always returns false.

What is wrong with my code?
And is there a better function to check, to know if Creators Update is installed?

UPDATE: I followed Microsoft guidelines for the above Fail, and changed the version checking from AnalyticsInfo.VersionInfo to Windows.Foundation.Metadata.ApiInformation. The app still fails the WACK test with the same error.

2ND UPDATE:
After updating Windows10 to Creators Update, Build 16251.0, this error disappeared on my computer.

like image 485
user1725145 Avatar asked Aug 03 '17 09:08

user1725145


1 Answers

Maybe a little bit helper class like this? Note calling this could be costly so it's recommended to do this once and cache the data.

(Update: If you use Windows Composition API, you will find AreEffectsFast and AreEffectsSupported helpful as you can use them to toggle effects on and off based on user's device and OS conditions. I have extended the class below to expose them as two new properties.)

public class BuildInfo
{
    private static BuildInfo _buildInfo;

    private BuildInfo()
    {
        if (ApiInformation.IsApiContractPresent("Windows.Foundation.UniversalApiContract", 5))
        {
            Build = Build.FallCreators;
        }
        else if (ApiInformation.IsApiContractPresent("Windows.Foundation.UniversalApiContract", 4))
        {
            Build = Build.Creators;
        }
        else if (ApiInformation.IsApiContractPresent("Windows.Foundation.UniversalApiContract", 3))
        {
            Build = Build.Anniversary;
        }
        else if (ApiInformation.IsApiContractPresent("Windows.Foundation.UniversalApiContract", 2))
        {
            Build = Build.Threshold2;
        }
        else if (ApiInformation.IsApiContractPresent("Windows.Foundation.UniversalApiContract", 1))
        {
            Build = Build.Threshold1;
        }
        else
        {
            Build = Build.Unknown;
        }

        if (!BeforeCreatorsUpdate)
        {
            var capabilities = CompositionCapabilities.GetForCurrentView();
            capabilities.Changed += (s, e) => UpdateCapabilities(capabilities);
            UpdateCapabilities(capabilities);
        }

        void UpdateCapabilities(CompositionCapabilities capabilities)
        {
            AreEffectsSupported = capabilities.AreEffectsSupported();
            AreEffectsFast = capabilities.AreEffectsFast();
        }
    }

    public static Build Build { get; private set; }
    public static bool AreEffectsFast { get; private set; }
    public static bool AreEffectsSupported { get; private set; }
    public static bool BeforeCreatorsUpdate => Build < Build.Creators;

    public static BuildInfo RetrieveApiInfo() => _buildInfo ?? (_buildInfo = new BuildInfo());
}

public enum Build
{
    Unknown = 0,
    Threshold1 = 1507,   // 10240
    Threshold2 = 1511,   // 10586
    Anniversary = 1607,  // 14393 Redstone 1
    Creators = 1703,     // 15063 Redstone 2
    FallCreators = 1709  // 16299 Redstone 3
}

To initialize the class, call it right after OnWindowCreated in your App.xaml.cs.

protected override void OnWindowCreated(WindowCreatedEventArgs args)
{
    BuildInfo.RetrieveBuildInfo();

To use it, simply call

if (BuildInfo.Build == Build.Anniversary) { ... }

if (BuildInfo.BeforeCreatorsUpdate) { ... }

if (BuildInfo.AreEffectsFast) { ... }
like image 67
Justin XL Avatar answered Oct 29 '22 09:10

Justin XL