diff --git a/DeviceTests/DeviceTests.Android/DeviceTests.Android.csproj b/DeviceTests/DeviceTests.Android/DeviceTests.Android.csproj index d3f02f833..4ba92430f 100644 --- a/DeviceTests/DeviceTests.Android/DeviceTests.Android.csproj +++ b/DeviceTests/DeviceTests.Android/DeviceTests.Android.csproj @@ -65,7 +65,7 @@ - + @@ -74,8 +74,8 @@ - - + + diff --git a/DeviceTests/DeviceTests.Shared/Barometer_Shared.cs b/DeviceTests/DeviceTests.Shared/Barometer_Shared.cs index 7567944dc..9095a430a 100644 --- a/DeviceTests/DeviceTests.Shared/Barometer_Shared.cs +++ b/DeviceTests/DeviceTests.Shared/Barometer_Shared.cs @@ -29,7 +29,7 @@ void Barometer_ReadingChanged(object sender, BarometerChangedEventArgs e) var d = await tcs.Task; - Assert.True(d.Pressure >= 0); + Assert.True(d.PressureInHectopascals >= 0); Barometer.Stop(); Barometer.ReadingChanged -= Barometer_ReadingChanged; } diff --git a/DeviceTests/DeviceTests.Shared/Battery_Tests.cs b/DeviceTests/DeviceTests.Shared/Battery_Tests.cs index 592a75178..ca11c6c78 100644 --- a/DeviceTests/DeviceTests.Shared/Battery_Tests.cs +++ b/DeviceTests/DeviceTests.Shared/Battery_Tests.cs @@ -42,5 +42,11 @@ public void Charge_Power() Assert.NotEqual(BatteryPowerSource.Unknown, Battery.PowerSource); } + + [Fact] + public void App_Is_Not_Lower_Power_mode() + { + Assert.Equal(EnergySaverStatus.Off, Battery.EnergySaverStatus); + } } } diff --git a/DeviceTests/DeviceTests.Shared/Clipboard_Tests.cs b/DeviceTests/DeviceTests.Shared/Clipboard_Tests.cs index 0bfac6b0e..83ae4dd8e 100644 --- a/DeviceTests/DeviceTests.Shared/Clipboard_Tests.cs +++ b/DeviceTests/DeviceTests.Shared/Clipboard_Tests.cs @@ -13,10 +13,7 @@ public Task Set_Clipboard_Values(string text) { return Utils.OnMainThread(async () => { - Clipboard.SetText(text); - - await Task.Delay(100); - + await Clipboard.SetTextAsync(text); Assert.True(Clipboard.HasText); }); } @@ -28,7 +25,7 @@ public Task Get_Clipboard_Values(string text) { return Utils.OnMainThread(async () => { - Clipboard.SetText(text); + await Clipboard.SetTextAsync(text); var clipText = await Clipboard.GetTextAsync(); Assert.NotNull(clipText); diff --git a/DeviceTests/DeviceTests.Shared/Connectivity_Tests.cs b/DeviceTests/DeviceTests.Shared/Connectivity_Tests.cs index 2372d3e41..cc224152b 100644 --- a/DeviceTests/DeviceTests.Shared/Connectivity_Tests.cs +++ b/DeviceTests/DeviceTests.Shared/Connectivity_Tests.cs @@ -11,7 +11,7 @@ public void Network_Access() => Assert.Equal(NetworkAccess.Internet, Connectivity.NetworkAccess); [Fact] - public void Profiles() => - Assert.True(Connectivity.Profiles.Count() > 0); + public void ConnectionProfiles() => + Assert.True(Connectivity.ConnectionProfiles.Count() > 0); } } diff --git a/DeviceTests/DeviceTests.Shared/DeviceInfo_Tests.cs b/DeviceTests/DeviceTests.Shared/DeviceInfo_Tests.cs index 18c57653e..871d28524 100644 --- a/DeviceTests/DeviceTests.Shared/DeviceInfo_Tests.cs +++ b/DeviceTests/DeviceTests.Shared/DeviceInfo_Tests.cs @@ -68,11 +68,11 @@ public void AppPackageName_Is_Correct() public void Platform_Is_Correct() { #if WINDOWS_UWP - Assert.Equal(DeviceInfo.Platforms.UWP, DeviceInfo.Platform); + Assert.Equal(DevicePlatform.UWP, DeviceInfo.Platform); #elif __IOS__ - Assert.Equal(DeviceInfo.Platforms.iOS, DeviceInfo.Platform); + Assert.Equal(DevicePlatform.iOS, DeviceInfo.Platform); #elif __ANDROID__ - Assert.Equal(DeviceInfo.Platforms.Android, DeviceInfo.Platform); + Assert.Equal(DevicePlatform.Android, DeviceInfo.Platform); #else throw new PlatformNotSupportedException(); #endif @@ -96,12 +96,56 @@ public Task Screen_Metrics_Are_Not_Null() { return Utils.OnMainThread(() => { - var metrics = DeviceDisplay.ScreenMetrics; + var metrics = DeviceDisplay.MainDisplayInfo; Assert.True(metrics.Width > 0); Assert.True(metrics.Height > 0); Assert.True(metrics.Density > 0); }); } + + [Fact] + public Task ScreenLock_Locks() + { + return Utils.OnMainThread(() => + { + Assert.False(DeviceDisplay.KeepScreenOn); + + DeviceDisplay.KeepScreenOn = true; + Assert.True(DeviceDisplay.KeepScreenOn); + + DeviceDisplay.KeepScreenOn = false; + Assert.False(DeviceDisplay.KeepScreenOn); + }); + } + + [Fact] + public Task ScreenLock_Unlocks_Without_Locking() + { + return Utils.OnMainThread(() => + { + Assert.False(DeviceDisplay.KeepScreenOn); + + DeviceDisplay.KeepScreenOn = false; + Assert.False(DeviceDisplay.KeepScreenOn); + }); + } + + [Fact] + public Task ScreenLock_Locks_Only_Once() + { + return Utils.OnMainThread(() => + { + Assert.False(DeviceDisplay.KeepScreenOn); + + DeviceDisplay.KeepScreenOn = true; + Assert.True(DeviceDisplay.KeepScreenOn); + DeviceDisplay.KeepScreenOn = true; + Assert.True(DeviceDisplay.KeepScreenOn); + + DeviceDisplay.KeepScreenOn = false; + Assert.False(DeviceDisplay.KeepScreenOn); + }); + } } } diff --git a/DeviceTests/DeviceTests.Shared/DeviceTests.Shared.csproj b/DeviceTests/DeviceTests.Shared/DeviceTests.Shared.csproj index 045176e6a..2ad635c8e 100644 --- a/DeviceTests/DeviceTests.Shared/DeviceTests.Shared.csproj +++ b/DeviceTests/DeviceTests.Shared/DeviceTests.Shared.csproj @@ -29,17 +29,17 @@ pdbonly - + - - - + + + - + Windows Mobile Extensions for the UWP diff --git a/DeviceTests/DeviceTests.Shared/Geocoding_Tests.cs b/DeviceTests/DeviceTests.Shared/Geocoding_Tests.cs index 7a9fc20c6..8afe13aa5 100644 --- a/DeviceTests/DeviceTests.Shared/Geocoding_Tests.cs +++ b/DeviceTests/DeviceTests.Shared/Geocoding_Tests.cs @@ -9,7 +9,9 @@ public class Geocoding_Tests { public Geocoding_Tests() { - Geocoding.MapKey = "RJHqIE53Onrqons5CNOx~FrDr3XhjDTyEXEjng-CRoA~Aj69MhNManYUKxo6QcwZ0wmXBtyva0zwuHB04rFYAPf7qqGJ5cHb03RCDw1jIW8l"; +#if WINDOWS_UWP + Platform.MapServiceToken = "RJHqIE53Onrqons5CNOx~FrDr3XhjDTyEXEjng-CRoA~Aj69MhNManYUKxo6QcwZ0wmXBtyva0zwuHB04rFYAPf7qqGJ5cHb03RCDw1jIW8l"; +#endif } [Theory] diff --git a/DeviceTests/DeviceTests.Shared/Maps_Tests.cs b/DeviceTests/DeviceTests.Shared/Maps_Tests.cs index cf1e0a9c8..ec06693cb 100644 --- a/DeviceTests/DeviceTests.Shared/Maps_Tests.cs +++ b/DeviceTests/DeviceTests.Shared/Maps_Tests.cs @@ -15,7 +15,7 @@ public class Maps_Tests [Trait(Traits.InteractionType, Traits.InteractionTypes.Human)] public async Task LaunchMap_CoordinatesDisplayCorrectPlace() { - await Maps.OpenAsync(testLatitude, testLongitude, new MapsLaunchOptions { Name = mapName }); + await Map.OpenAsync(testLatitude, testLongitude, new MapLaunchOptions { Name = mapName }); } [Fact] @@ -29,28 +29,28 @@ public async Task LaunchMap_PlacemarkDisplayCorrectPlace() Thoroughfare = "Microsoft Building 25", Locality = "Redmond" }; - await Maps.OpenAsync(placemark, new MapsLaunchOptions { Name = mapName }); + await Map.OpenAsync(placemark, new MapLaunchOptions { Name = mapName }); } [Fact] public async Task LaunchMap_NullLocation() { Location location = null; - await Assert.ThrowsAsync(() => Maps.OpenAsync(location)); + await Assert.ThrowsAsync(() => Map.OpenAsync(location)); } [Fact] public async Task LaunchMap_NullOptionsLocation() { var location = new Location(testLatitude, testLongitude); - await Assert.ThrowsAsync(() => Maps.OpenAsync(location, null)); + await Assert.ThrowsAsync(() => Map.OpenAsync(location, null)); } [Fact] public async Task LaunchMap_NullPlacemark() { Placemark location = null; - await Assert.ThrowsAsync(() => Maps.OpenAsync(location)); + await Assert.ThrowsAsync(() => Map.OpenAsync(location)); } [Fact] @@ -63,7 +63,7 @@ public async Task LaunchMap_NullOptionsPlacemark() Thoroughfare = "Microsoft Building 25", Locality = "Redmond" }; - await Assert.ThrowsAsync(() => Maps.OpenAsync(placemark, null)); + await Assert.ThrowsAsync(() => Map.OpenAsync(placemark, null)); } } } diff --git a/DeviceTests/DeviceTests.Shared/Power_Tests.cs b/DeviceTests/DeviceTests.Shared/Power_Tests.cs deleted file mode 100644 index b1c7164b7..000000000 --- a/DeviceTests/DeviceTests.Shared/Power_Tests.cs +++ /dev/null @@ -1,14 +0,0 @@ -using Xamarin.Essentials; -using Xunit; - -namespace DeviceTests -{ - public class Power_Tests - { - [Fact] - public void App_Is_Not_Lower_Power_mode() - { - Assert.Equal(EnergySaverStatus.Off, Power.EnergySaverStatus); - } - } -} diff --git a/DeviceTests/DeviceTests.Shared/ScreenLock_Tests.cs b/DeviceTests/DeviceTests.Shared/ScreenLock_Tests.cs deleted file mode 100644 index b212cc561..000000000 --- a/DeviceTests/DeviceTests.Shared/ScreenLock_Tests.cs +++ /dev/null @@ -1,53 +0,0 @@ -using System.Threading.Tasks; -using Xamarin.Essentials; -using Xunit; - -namespace DeviceTests -{ - public class ScreenLock_Tests - { - [Fact] - public Task ScreenLock_Locks() - { - return Utils.OnMainThread(() => - { - Assert.False(ScreenLock.IsActive); - - ScreenLock.RequestActive(); - Assert.True(ScreenLock.IsActive); - - ScreenLock.RequestRelease(); - Assert.False(ScreenLock.IsActive); - }); - } - - [Fact] - public Task ScreenLock_Unlocks_Without_Locking() - { - return Utils.OnMainThread(() => - { - Assert.False(ScreenLock.IsActive); - - ScreenLock.RequestRelease(); - Assert.False(ScreenLock.IsActive); - }); - } - - [Fact] - public Task ScreenLock_Locks_Only_Once() - { - return Utils.OnMainThread(() => - { - Assert.False(ScreenLock.IsActive); - - ScreenLock.RequestActive(); - Assert.True(ScreenLock.IsActive); - ScreenLock.RequestActive(); - Assert.True(ScreenLock.IsActive); - - ScreenLock.RequestRelease(); - Assert.False(ScreenLock.IsActive); - }); - } - } -} diff --git a/DeviceTests/DeviceTests.Shared/SecureStorage_Tests.cs b/DeviceTests/DeviceTests.Shared/SecureStorage_Tests.cs index 01bf35d95..43e616684 100644 --- a/DeviceTests/DeviceTests.Shared/SecureStorage_Tests.cs +++ b/DeviceTests/DeviceTests.Shared/SecureStorage_Tests.cs @@ -6,6 +6,11 @@ namespace DeviceTests { public class SecureStorage_Tests { + public SecureStorage_Tests() + { + SecureStorage.RemoveAll(); + } + [Theory] [InlineData("test.txt", "data", true, true)] [InlineData("noextension", "data2", true, false)] @@ -40,6 +45,32 @@ public async Task Saves_And_Loads(string key, string data, bool emulatePreApi23, Assert.Equal(data, c); } +#if __ANDROID__ + [Theory] + [InlineData("test.txt", "data")] + public async Task Fix_Corrupt_Key(string key, string data) + { + // set a valid key + SecureStorage.AlwaysUseAsymmetricKeyStorage = true; + await SecureStorage.SetAsync(key, data); + + // simulate corrupt the key + var prefKey = "SecureStorageKey"; + var mainKey = "A2PfJSNdEDjM+422tpu7FqFcVQQbO3ti/DvnDnIqrq9CFwaBi6NdXYcicjvMW6nF7X/Clpto5xerM41U1H4qtWJDO0Ijc5QNTHGZl9tDSbXJ6yDCDDnEDryj2uTa8DiHoNcNX68QtcV3at4kkJKXXAwZXSC88a73/xDdh1u5gUdCeXJzVc5vOY6QpAGUH0bjR5NHrqEQNNGDdquFGN9n2ZJPsEK6C9fx0QwCIL+uldpAYSWrpmUIr+/0X7Y0mJpN84ldygEVxHLBuVrzB4Bbu5XGLUN/0Sr2plWcKm7XhM6wp3JRW6Eae2ozys42p1YLeM0HXWrhTqP6FRPkS6mOtw=="; + + Preferences.Set(prefKey, mainKey, SecureStorage.Alias); + + var c = await SecureStorage.GetAsync(key); + Assert.Null(c); + + // try to reset and get again + await SecureStorage.SetAsync(key, data); + c = await SecureStorage.GetAsync(key); + + Assert.Equal(data, c); + } +#endif + [Theory] [InlineData(true)] [InlineData(false)] diff --git a/DeviceTests/DeviceTests.Shared/Vibration_Tests.cs b/DeviceTests/DeviceTests.Shared/Vibration_Tests.cs index 815a86c03..a2371308f 100644 --- a/DeviceTests/DeviceTests.Shared/Vibration_Tests.cs +++ b/DeviceTests/DeviceTests.Shared/Vibration_Tests.cs @@ -17,7 +17,7 @@ public void Vibrate() #elif __IOS__ // TODO: remove this as soon as the test harness can filter // the iOS simulator does not emulate a flashlight - if (DeviceInfo.DeviceType == DeviceType.Virtual && DeviceInfo.Platform == DeviceInfo.Platforms.iOS) + if (DeviceInfo.DeviceType == DeviceType.Virtual && DeviceInfo.Platform == DevicePlatform.iOS) return; #endif @@ -35,7 +35,7 @@ public void Vibrate_Cancel() #elif __IOS__ // TODO: remove this as soon as the test harness can filter // the iOS simulator does not emulate a flashlight - if (DeviceInfo.DeviceType == DeviceType.Virtual && DeviceInfo.Platform == DeviceInfo.Platforms.iOS) + if (DeviceInfo.DeviceType == DeviceType.Virtual && DeviceInfo.Platform == DevicePlatform.iOS) return; #endif diff --git a/DeviceTests/DeviceTests.UWP/DeviceTests.UWP.csproj b/DeviceTests/DeviceTests.UWP/DeviceTests.UWP.csproj index ea181c333..47eec6b4f 100644 --- a/DeviceTests/DeviceTests.UWP/DeviceTests.UWP.csproj +++ b/DeviceTests/DeviceTests.UWP/DeviceTests.UWP.csproj @@ -127,10 +127,10 @@ - - - - + + + + diff --git a/DeviceTests/DeviceTests.iOS/DeviceTests.iOS.csproj b/DeviceTests/DeviceTests.iOS/DeviceTests.iOS.csproj index bd81986ae..27923203a 100644 --- a/DeviceTests/DeviceTests.iOS/DeviceTests.iOS.csproj +++ b/DeviceTests/DeviceTests.iOS/DeviceTests.iOS.csproj @@ -110,9 +110,9 @@ - - - + + + diff --git a/README.md b/README.md index b7b7c841e..f5999c9be 100644 --- a/README.md +++ b/README.md @@ -67,7 +67,6 @@ The following cross-platform APIs are available in Xamarin.Essentials: * [Open Browser](https://docs.microsoft.com/xamarin/essentials/open-browser) * [Orientation Sensor](https://docs.microsoft.com/en-us/xamarin/essentials/orientation-sensor) * [Phone Dialer](https://docs.microsoft.com/xamarin/essentials/phone-dialer) -* [Power](https://docs.microsoft.com/en-us/xamarin/essentials/power) * [Preferences](https://docs.microsoft.com/xamarin/essentials/preferences) * [Screen Lock](https://docs.microsoft.com/xamarin/essentials/screen-lock) * [Secure Storage](https://docs.microsoft.com/xamarin/essentials/secure-storage) diff --git a/Samples/Samples.Android/Samples.Android.csproj b/Samples/Samples.Android/Samples.Android.csproj index b3bf5896d..584c92bac 100644 --- a/Samples/Samples.Android/Samples.Android.csproj +++ b/Samples/Samples.Android/Samples.Android.csproj @@ -33,8 +33,8 @@ false false true - false - true + true + false true @@ -74,19 +74,11 @@ - - 1.10.0 - - - 1.10.0 - - - 1.10.0 - - - 1.10.0 - - + + + + + diff --git a/Samples/Samples.UWP/MainPage.xaml.cs b/Samples/Samples.UWP/MainPage.xaml.cs index 208683b47..cd0e977ae 100644 --- a/Samples/Samples.UWP/MainPage.xaml.cs +++ b/Samples/Samples.UWP/MainPage.xaml.cs @@ -1,4 +1,6 @@ -namespace Samples.UWP +using Xamarin.Essentials; + +namespace Samples.UWP { public sealed partial class MainPage : Xamarin.Forms.Platform.UWP.WindowsPage { @@ -6,6 +8,8 @@ public MainPage() { InitializeComponent(); + Platform.MapServiceToken = "RJHqIE53Onrqons5CNOx~FrDr3XhjDTyEXEjng-CRoA~Aj69MhNManYUKxo6QcwZ0wmXBtyva0zwuHB04rFYAPf7qqGJ5cHb03RCDw1jIW8l"; + LoadApplication(new Samples.App()); } } diff --git a/Samples/Samples.UWP/Samples.UWP.csproj b/Samples/Samples.UWP/Samples.UWP.csproj index 891d03dc1..5e43d9dbd 100644 --- a/Samples/Samples.UWP/Samples.UWP.csproj +++ b/Samples/Samples.UWP/Samples.UWP.csproj @@ -126,19 +126,11 @@ true - - 1.10.0 - - - 1.10.0 - - - 1.10.0 - - - 1.10.0 - - + + + + + diff --git a/Samples/Samples.iOS/Samples.iOS.csproj b/Samples/Samples.iOS/Samples.iOS.csproj index f0d2a0d26..e5164258f 100644 --- a/Samples/Samples.iOS/Samples.iOS.csproj +++ b/Samples/Samples.iOS/Samples.iOS.csproj @@ -98,19 +98,11 @@ - - 1.10.0 - - - 1.10.0 - - - 1.10.0 - - - 1.10.0 - - + + + + + diff --git a/Samples/Samples/App.xaml.cs b/Samples/Samples/App.xaml.cs index 89a4fa61f..068b4160f 100644 --- a/Samples/Samples/App.xaml.cs +++ b/Samples/Samples/App.xaml.cs @@ -38,9 +38,6 @@ protected override void OnStart() typeof(Crashes), typeof(Distribute)); } - - // set UWP Map Key - Geocoding.MapKey = "RJHqIE53Onrqons5CNOx~FrDr3XhjDTyEXEjng-CRoA~Aj69MhNManYUKxo6QcwZ0wmXBtyva0zwuHB04rFYAPf7qqGJ5cHb03RCDw1jIW8l"; } protected override void OnSleep() diff --git a/Samples/Samples/Samples.csproj b/Samples/Samples/Samples.csproj index 7f9d31395..ed3c1829a 100644 --- a/Samples/Samples/Samples.csproj +++ b/Samples/Samples/Samples.csproj @@ -23,7 +23,7 @@ - + diff --git a/Samples/Samples/View/AllSensorsPage.xaml b/Samples/Samples/View/AllSensorsPage.xaml index 932a63741..d3494eb06 100644 --- a/Samples/Samples/View/AllSensorsPage.xaml +++ b/Samples/Samples/View/AllSensorsPage.xaml @@ -63,7 +63,7 @@