Skip to content
This repository has been archived by the owner on May 15, 2024. It is now read-only.

Commit

Permalink
Merge branch 'main' into jamesmontemagno-patch-2
Browse files Browse the repository at this point in the history
  • Loading branch information
mattleibow authored Jul 12, 2021
2 parents 3c8f1ca + 1dc7f97 commit 02ba4fa
Show file tree
Hide file tree
Showing 13 changed files with 102 additions and 46 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using Foundation;

#pragma warning disable CS0618 // Type or member is obsolete
[assembly: LinkerSafe]
#pragma warning restore CS0618 // Type or member is obsolete
15 changes: 12 additions & 3 deletions Xamarin.Essentials/DeviceDisplay/DeviceDisplay.android.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Diagnostics;
using Android.Content;
using Android.Content.Res;
using Android.Provider;
Expand Down Expand Up @@ -92,9 +93,17 @@ static DisplayOrientation CalculateOrientation()

static Display GetDefaultDisplay()
{
using var service = Platform.AppContext.GetSystemService(Context.WindowService);
using var windowManager = service?.JavaCast<IWindowManager>();
return windowManager?.DefaultDisplay;
try
{
using var service = Platform.AppContext.GetSystemService(Context.WindowService);
using var windowManager = service?.JavaCast<IWindowManager>();
return windowManager?.DefaultDisplay;
}
catch (Exception ex)
{
Debug.WriteLine($"Unable to get default display: {ex}");
return null;
}
}
}

Expand Down
11 changes: 7 additions & 4 deletions Xamarin.Essentials/MediaPicker/MediaPicker.ios.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ static async Task<FileResult> PhotoAsync(MediaPickerOptions options, bool photo,
if (!UIImagePickerController.AvailableMediaTypes(sourceType).Contains(mediaType))
throw new FeatureNotSupportedException();

if (!photo)
if (!photo && !pickExisting)
// microphone only needed if video will be captured
await Permissions.EnsureGrantedAsync<Permissions.Microphone>();

// Check if picking existing or not and ensure permission accordingly as they can be set independently from each other
Expand Down Expand Up @@ -65,7 +66,11 @@ static async Task<FileResult> PhotoAsync(MediaPickerOptions options, bool photo,
var tcs = new TaskCompletionSource<FileResult>(picker);
picker.Delegate = new PhotoPickerDelegate
{
CompletedHandler = info => GetFileResult(info, tcs)
CompletedHandler = async info =>
{
GetFileResult(info, tcs);
await vc.DismissViewControllerAsync(true);
}
};

if (picker.PresentationController != null)
Expand All @@ -80,8 +85,6 @@ static async Task<FileResult> PhotoAsync(MediaPickerOptions options, bool photo,

var result = await tcs.Task;

await vc.DismissViewControllerAsync(true);

picker?.Dispose();
picker = null;

Expand Down
8 changes: 4 additions & 4 deletions Xamarin.Essentials/PhoneDialer/PhoneDialer.android.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,21 +28,21 @@ static void PlatformOpen(string number)
var phoneNumber = string.Empty;
#if __ANDROID_24__
if (Platform.HasApiLevelN)
phoneNumber = PhoneNumberUtils.FormatNumber(number, Java.Util.Locale.GetDefault(Java.Util.Locale.Category.Format).Country);
phoneNumber = PhoneNumberUtils.FormatNumber(number, Java.Util.Locale.GetDefault(Java.Util.Locale.Category.Format).Country) ?? phoneNumber;
else if (Platform.HasApiLevel(BuildVersionCodes.Lollipop))
#else
if (Platform.HasApiLevel(BuildVersionCodes.Lollipop))
#endif

phoneNumber = PhoneNumberUtils.FormatNumber(number, Java.Util.Locale.Default.Country);
phoneNumber = PhoneNumberUtils.FormatNumber(number, Java.Util.Locale.Default.Country) ?? phoneNumber;
else
#pragma warning disable CS0618
phoneNumber = PhoneNumberUtils.FormatNumber(number);
phoneNumber = PhoneNumberUtils.FormatNumber(number) ?? phoneNumber;
#pragma warning restore CS0618

// if we are an extension then we need to encode
if (phoneNumber.Contains(',') || phoneNumber.Contains(';'))
phoneNumber = URLEncoder.Encode(phoneNumber, "UTF-8");
phoneNumber = URLEncoder.Encode(phoneNumber, "UTF-8") ?? phoneNumber;

var dialIntent = ResolveDialIntent(phoneNumber);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,10 @@ internal static bool OnResume(Intent intent)
}
}

static async Task<WebAuthenticatorResult> PlatformAuthenticateAsync(Uri url, Uri callbackUrl)
static async Task<WebAuthenticatorResult> PlatformAuthenticateAsync(WebAuthenticatorOptions webAuthenticatorOptions)
{
var url = webAuthenticatorOptions?.Url;
var callbackUrl = webAuthenticatorOptions?.CallbackUrl;
var packageName = Platform.AppContext.PackageName;

// Create an intent to see if the app developer wired up the callback activity correctly
Expand Down
33 changes: 32 additions & 1 deletion Xamarin.Essentials/WebAuthenticator/WebAuthenticator.ios.tvos.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using SafariServices;
#endif
using UIKit;
using WebKit;

namespace Xamarin.Essentials
{
Expand Down Expand Up @@ -36,8 +37,12 @@ public static partial class WebAuthenticator
static SFAuthenticationSession sf;
#endif

internal static async Task<WebAuthenticatorResult> PlatformAuthenticateAsync(Uri url, Uri callbackUrl)
internal static async Task<WebAuthenticatorResult> PlatformAuthenticateAsync(WebAuthenticatorOptions webAuthenticatorOptions)
{
var url = webAuthenticatorOptions?.Url;
var callbackUrl = webAuthenticatorOptions?.CallbackUrl;
var prefersEphemeralWebBrowserSession = webAuthenticatorOptions?.PrefersEphemeralWebBrowserSession ?? false;

if (!VerifyHasUrlSchemeOrDoesntRequire(callbackUrl.Scheme))
throw new InvalidOperationException("You must register your URL Scheme handler in your app's Info.plist.");

Expand Down Expand Up @@ -73,6 +78,11 @@ static void AuthSessionCallback(NSUrl cbUrl, NSError error)
{
var ctx = new ContextProvider(Platform.GetCurrentWindow());
void_objc_msgSend_IntPtr(was.Handle, ObjCRuntime.Selector.GetHandle("setPresentationContextProvider:"), ctx.Handle);
was.PrefersEphemeralWebBrowserSession = prefersEphemeralWebBrowserSession;
}
else if (prefersEphemeralWebBrowserSession)
{
ClearCookies();
}

using (was)
Expand All @@ -82,6 +92,9 @@ static void AuthSessionCallback(NSUrl cbUrl, NSError error)
}
}

if (prefersEphemeralWebBrowserSession)
ClearCookies();

if (UIDevice.CurrentDevice.CheckSystemVersion(11, 0))
{
sf = new SFAuthenticationSession(WebUtils.GetNativeUrl(url), scheme, AuthSessionCallback);
Expand Down Expand Up @@ -115,6 +128,24 @@ static void AuthSessionCallback(NSUrl cbUrl, NSError error)
#endif

return await tcsResponse.Task;

void ClearCookies()
{
NSUrlCache.SharedCache.RemoveAllCachedResponses();

#if __IOS__
if (UIDevice.CurrentDevice.CheckSystemVersion(11, 0))
{
WKWebsiteDataStore.DefaultDataStore.HttpCookieStore.GetAllCookies((cookies) =>
{
foreach (var cookie in cookies)
{
WKWebsiteDataStore.DefaultDataStore.HttpCookieStore.DeleteCookie(cookie, null);
}
});
}
#endif
}
}

internal static bool OpenUrl(Uri uri)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@ static WebAuthenticator()
callbackHelper.Register();
}

internal static async Task<WebAuthenticatorResult> PlatformAuthenticateAsync(Uri url, Uri callbackUrl)
internal static async Task<WebAuthenticatorResult> PlatformAuthenticateAsync(WebAuthenticatorOptions webAuthenticatorOptions)
{
var url = webAuthenticatorOptions?.Url;
var callbackUrl = webAuthenticatorOptions?.CallbackUrl;
if (!AppInfo.VerifyHasUrlScheme(callbackUrl.Scheme))
throw new InvalidOperationException("You must register your URL Scheme handler in your app's Info.plist!");

Expand Down Expand Up @@ -57,6 +59,8 @@ static void AuthSessionCallback(NSUrl cbUrl, NSError error)
var ctx = new ContextProvider(Platform.GetCurrentWindow());
was.PresentationContextProvider = ctx;

was.PrefersEphemeralWebBrowserSession = webAuthenticatorOptions?.PrefersEphemeralWebBrowserSession ?? false;

was.Start();
return await tcsResponse.Task;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace Xamarin.Essentials
{
public static partial class WebAuthenticator
{
static Task<WebAuthenticatorResult> PlatformAuthenticateAsync(Uri url, Uri callbackUrl)
static Task<WebAuthenticatorResult> PlatformAuthenticateAsync(WebAuthenticatorOptions webAuthenticatorOptions)
=> throw ExceptionUtils.NotSupportedOrImplementedException;
}
}
14 changes: 13 additions & 1 deletion Xamarin.Essentials/WebAuthenticator/WebAuthenticator.shared.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,18 @@ namespace Xamarin.Essentials
public static partial class WebAuthenticator
{
public static Task<WebAuthenticatorResult> AuthenticateAsync(Uri url, Uri callbackUrl)
=> PlatformAuthenticateAsync(url, callbackUrl);
=> PlatformAuthenticateAsync(new WebAuthenticatorOptions { Url = url, CallbackUrl = callbackUrl });

public static Task<WebAuthenticatorResult> AuthenticateAsync(WebAuthenticatorOptions webAuthenticatorOptions)
=> PlatformAuthenticateAsync(webAuthenticatorOptions);
}

public class WebAuthenticatorOptions
{
public Uri Url { get; set; }

public Uri CallbackUrl { get; set; }

public bool PrefersEphemeralWebBrowserSession { get; set; }
}
}
5 changes: 4 additions & 1 deletion Xamarin.Essentials/WebAuthenticator/WebAuthenticator.uwp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,11 @@ namespace Xamarin.Essentials
{
public static partial class WebAuthenticator
{
static async Task<WebAuthenticatorResult> PlatformAuthenticateAsync(Uri url, Uri callbackUrl)
static async Task<WebAuthenticatorResult> PlatformAuthenticateAsync(WebAuthenticatorOptions webAuthenticatorOptions)
{
var url = webAuthenticatorOptions?.Url;
var callbackUrl = webAuthenticatorOptions?.CallbackUrl;

if (!IsUriProtocolDeclared(callbackUrl.Scheme))
throw new InvalidOperationException($"You need to declare the windows.protocol usage of the protocol/scheme `{callbackUrl.Scheme}` in your AppxManifest.xml file");

Expand Down
14 changes: 2 additions & 12 deletions Xamarin.Essentials/Xamarin.Essentials.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="MSBuild.Sdk.Extras/3.0.22">
<PropertyGroup>
<TargetFrameworks>netstandard1.0;netstandard2.0;Xamarin.iOS10;Xamarin.TVOS10;Xamarin.WatchOS10;MonoAndroid80;MonoAndroid81;MonoAndroid90;MonoAndroid10.0;tizen40;Xamarin.Mac20;</TargetFrameworks>
<TargetFrameworks>netstandard1.0;netstandard2.0;Xamarin.iOS10;Xamarin.TVOS10;Xamarin.WatchOS10;MonoAndroid10.0;tizen40;Xamarin.Mac20;</TargetFrameworks>
<TargetFrameworks Condition=" '$(OS)' == 'Windows_NT' ">$(TargetFrameworks);uap10.0.16299;</TargetFrameworks>
<AssemblyName>Xamarin.Essentials</AssemblyName>
<RootNamespace>Xamarin.Essentials</RootNamespace>
Expand Down Expand Up @@ -77,17 +77,7 @@
<PackageReference Include="System.Numerics.Vectors" Version="4.5.0" />
<Reference Include="System.Numerics" />
<AndroidResource Include="Resources\xml\*.xml" />
</ItemGroup>
<!-- NOTE: When Android 11.x comes out we neeed to make this check more robust -->
<ItemGroup Condition="$(TargetFramework.StartsWith('MonoAndroid')) And '$(TargetFramework)' != 'MonoAndroid10.0'">
<PackageReference Include="Xamarin.Android.Support.Compat" Version="28.0.0.3" />
<PackageReference Include="Xamarin.Android.Support.CustomTabs" Version="28.0.0.3" />
<PackageReference Condition=" '$(OS)' == 'Windows_NT' And $(TargetFrameworkVersion.TrimStart('vV')) &lt; 9.0 And $(TargetFrameworkVersion.TrimStart('vV')) &lt; 10.0" Include="Xamarin.Android.Support.Core.Utils" Version="28.0.0.3" />
<PackageReference Condition=" '$(OS)' != 'Windows_NT' " Include="Xamarin.Android.Support.Core.Utils" Version="28.0.0.3" />
</ItemGroup>
<!-- NOTE: When Android 11.x comes out we neeed to make this check more robust -->
<ItemGroup Condition="'$(TargetFramework)' == 'MonoAndroid10.0'">
<PackageReference Include="Xamarin.AndroidX.Browser" Version="1.3.0" />
<PackageReference Include="Xamarin.AndroidX.Browser" Version="[1.3.0.5,1.4)" />
</ItemGroup>
<ItemGroup Condition=" $(TargetFramework.StartsWith('Xamarin.iOS')) ">
<Compile Include="**\*.ios.cs" />
Expand Down
32 changes: 16 additions & 16 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -133,22 +133,22 @@ stages:
- bash: sh -c "echo \"y\" | $ANDROID_HOME/tools/bin/sdkmanager \"system-images;android-22;google_apis;x86\""
displayName: Install the Android emulators

- template: .ci/build.yml@components
parameters:
name: devicetests_android_api_23
runChecks: false
continueOnError: true
displayName: Android API 23
publishOutputSuffix: '-android23'
windowsImage: ''
areaPath: $(AREA_PATH)
verbosity: diagnostic
cakeFile: DeviceTests/build.cake
cakeTarget: test-android-emu
cakeExtraArgs: --avd-target="`"system-images;android-23;google_apis;x86`""
preBuildSteps:
- bash: sh -c "echo \"y\" | $ANDROID_HOME/tools/bin/sdkmanager \"system-images;android-23;google_apis;x86\""
displayName: Install the Android emulators
# - template: .ci/build.yml@components
# parameters:
# name: devicetests_android_api_23
# runChecks: false
# continueOnError: true
# displayName: Android API 23
# publishOutputSuffix: '-android23'
# windowsImage: ''
# areaPath: $(AREA_PATH)
# verbosity: diagnostic
# cakeFile: DeviceTests/build.cake
# cakeTarget: test-android-emu
# cakeExtraArgs: --avd-target="`"system-images;android-23;google_apis;x86`""
# preBuildSteps:
# - bash: sh -c "echo \"y\" | $ANDROID_HOME/tools/bin/sdkmanager \"system-images;android-23;google_apis;x86\""
# displayName: Install the Android emulators

- template: .ci/build.yml@components
parameters:
Expand Down
2 changes: 1 addition & 1 deletion docs/en/Xamarin.Essentials/FileBase.xml
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@
<ReturnType>System.String</ReturnType>
</ReturnValue>
<Docs>
<summary>Gets the full path and filename.</summary>
<summary>This property is purely informative, and does not always return the actual physical path to the file. To get the file, use OpenReadAsync method.</summary>
<value></value>
<remarks></remarks>
</Docs>
Expand Down

0 comments on commit 02ba4fa

Please sign in to comment.