Merge branch 'feature/maui-migration' into feature/maui-migration-ios-ext-tap-workaround

This commit is contained in:
Federico Maccaroni 2023-12-07 17:41:53 -03:00
commit 15a306490d
No known key found for this signature in database
GPG key ID: 5D233F8F2B034536
7 changed files with 42 additions and 41 deletions

View file

@ -115,7 +115,6 @@
<Folder Include="Platforms\Android\Utilities\" /> <Folder Include="Platforms\Android\Utilities\" />
</ItemGroup> </ItemGroup>
<ItemGroup Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'android'"> <ItemGroup Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'android'">
<PackageReference Include="Plugin.CurrentActivity" Version="2.1.0.4" />
<PackageReference Include="Xamarin.AndroidX.AutoFill" Version="1.1.0.18" /> <PackageReference Include="Xamarin.AndroidX.AutoFill" Version="1.1.0.18" />
<PackageReference Include="Xamarin.AndroidX.Activity.Ktx" Version="1.7.2.1" /> <PackageReference Include="Xamarin.AndroidX.Activity.Ktx" Version="1.7.2.1" />
</ItemGroup> </ItemGroup>

View file

@ -12,7 +12,6 @@ using Bit.Core.Abstractions;
using Bit.Core.Services; using Bit.Core.Services;
using Bit.Core.Utilities; using Bit.Core.Utilities;
using Bit.Droid.Services; using Bit.Droid.Services;
using Plugin.CurrentActivity;
using Plugin.Fingerprint; using Plugin.Fingerprint;
using Xamarin.Android.Net; using Xamarin.Android.Net;
using System.Net.Http; using System.Net.Http;
@ -101,7 +100,6 @@ namespace Bit.Droid
{ {
base.OnCreate(); base.OnCreate();
Bootstrap(); Bootstrap();
CrossCurrentActivity.Current.Init(this);
} }
public void OnProviderInstallFailed(int errorCode, Intent recoveryIntent) public void OnProviderInstallFailed(int errorCode, Intent recoveryIntent)
@ -136,7 +134,7 @@ namespace Bit.Droid
// }); // });
// ZXing.Net.Mobile.Forms.Android.Platform.Init(); // ZXing.Net.Mobile.Forms.Android.Platform.Init();
//}); //});
CrossFingerprint.SetCurrentActivityResolver(() => CrossCurrentActivity.Current.Activity); CrossFingerprint.SetCurrentActivityResolver(() => Microsoft.Maui.ApplicationModel.Platform.CurrentActivity);
var preferencesStorage = new PreferencesStorageService(null); var preferencesStorage = new PreferencesStorageService(null);
var localAppDataFolderPath = System.Environment.GetFolderPath(System.Environment.SpecialFolder.LocalApplicationData); var localAppDataFolderPath = System.Environment.GetFolderPath(System.Environment.SpecialFolder.LocalApplicationData);

View file

@ -12,7 +12,6 @@ using Bit.Core.Enums;
using Bit.Core.Models.View; using Bit.Core.Models.View;
using Bit.Core.Utilities; using Bit.Core.Utilities;
using Bit.Droid.Autofill; using Bit.Droid.Autofill;
using Plugin.CurrentActivity;
using Application = Android.App.Application; using Application = Android.App.Application;
namespace Bit.Droid.Services namespace Bit.Droid.Services
@ -46,7 +45,7 @@ namespace Bit.Droid.Services
} }
try try
{ {
var activity = (MainActivity)CrossCurrentActivity.Current.Activity; var activity = (MainActivity)Microsoft.Maui.ApplicationModel.Platform.CurrentActivity;
var afm = (AutofillManager)activity.GetSystemService( var afm = (AutofillManager)activity.GetSystemService(
Java.Lang.Class.FromType(typeof(AutofillManager))); Java.Lang.Class.FromType(typeof(AutofillManager)));
return afm.IsEnabled && afm.HasEnabledAutofillServices; return afm.IsEnabled && afm.HasEnabledAutofillServices;
@ -65,7 +64,7 @@ namespace Bit.Droid.Services
} }
try try
{ {
var activity = (MainActivity)CrossCurrentActivity.Current.Activity; var activity = (MainActivity)Microsoft.Maui.ApplicationModel.Platform.CurrentActivity;
var type = Java.Lang.Class.FromType(typeof(AutofillManager)); var type = Java.Lang.Class.FromType(typeof(AutofillManager));
var manager = activity.GetSystemService(type) as AutofillManager; var manager = activity.GetSystemService(type) as AutofillManager;
return manager.IsAutofillSupported; return manager.IsAutofillSupported;
@ -78,7 +77,7 @@ namespace Bit.Droid.Services
public void Autofill(CipherView cipher) public void Autofill(CipherView cipher)
{ {
var activity = CrossCurrentActivity.Current.Activity as MauiAppCompatActivity; var activity = Microsoft.Maui.ApplicationModel.Platform.CurrentActivity as MauiAppCompatActivity;
if (activity == null) if (activity == null)
{ {
return; return;
@ -170,7 +169,7 @@ namespace Bit.Droid.Services
{ {
try try
{ {
var activity = (MainActivity)CrossCurrentActivity.Current.Activity; var activity = (MainActivity)Microsoft.Maui.ApplicationModel.Platform.CurrentActivity;
var type = Java.Lang.Class.FromType(typeof(AutofillManager)); var type = Java.Lang.Class.FromType(typeof(AutofillManager));
var manager = activity.GetSystemService(type) as AutofillManager; var manager = activity.GetSystemService(type) as AutofillManager;
manager.DisableAutofillServices(); manager.DisableAutofillServices();

View file

@ -18,7 +18,6 @@ using Bit.App.Utilities.Prompts;
using Bit.Core.Abstractions; using Bit.Core.Abstractions;
using Bit.Core.Enums; using Bit.Core.Enums;
using Bit.App.Droid.Utilities; using Bit.App.Droid.Utilities;
using Plugin.CurrentActivity;
using Microsoft.Maui.Controls.Compatibility.Platform.Android; using Microsoft.Maui.Controls.Compatibility.Platform.Android;
using Resource = Bit.Core.Resource; using Resource = Bit.Core.Resource;
using Application = Android.App.Application; using Application = Android.App.Application;
@ -66,7 +65,7 @@ namespace Bit.Droid.Services
_toast.Dispose(); _toast.Dispose();
_toast = null; _toast = null;
} }
_toast = Android.Widget.Toast.MakeText(CrossCurrentActivity.Current.Activity, text, _toast = Android.Widget.Toast.MakeText(Microsoft.Maui.ApplicationModel.Platform.CurrentActivity, text,
longDuration ? ToastLength.Long : ToastLength.Short); longDuration ? ToastLength.Long : ToastLength.Short);
_toast.Show(); _toast.Show();
} }
@ -79,7 +78,7 @@ namespace Bit.Droid.Services
// https://developer.android.com/reference/android/content/pm/PackageManager#getLaunchIntentSenderForPackage(java.lang.String) // https://developer.android.com/reference/android/content/pm/PackageManager#getLaunchIntentSenderForPackage(java.lang.String)
return false; return false;
} }
var activity = CrossCurrentActivity.Current.Activity; var activity = Microsoft.Maui.ApplicationModel.Platform.CurrentActivity;
appName = appName.Replace("androidapp://", string.Empty); appName = appName.Replace("androidapp://", string.Empty);
var launchIntentSender = activity?.PackageManager?.GetLaunchIntentSenderForPackage(appName); var launchIntentSender = activity?.PackageManager?.GetLaunchIntentSenderForPackage(appName);
launchIntentSender?.SendIntent(activity, Result.Ok, null, null, null); launchIntentSender?.SendIntent(activity, Result.Ok, null, null, null);
@ -93,7 +92,7 @@ namespace Bit.Droid.Services
await HideLoadingAsync(); await HideLoadingAsync();
} }
var activity = CrossCurrentActivity.Current.Activity; var activity = Microsoft.Maui.ApplicationModel.Platform.CurrentActivity;
var inflater = (LayoutInflater)activity.GetSystemService(Context.LayoutInflaterService); var inflater = (LayoutInflater)activity.GetSystemService(Context.LayoutInflaterService);
var dialogView = inflater.Inflate(Resource.Layout.progress_dialog_layout, null); var dialogView = inflater.Inflate(Resource.Layout.progress_dialog_layout, null);
@ -159,7 +158,7 @@ namespace Bit.Droid.Services
} }
// Finally if all else fails, let's see if current activity is MainActivity // Finally if all else fails, let's see if current activity is MainActivity
if (CrossCurrentActivity.Current.Activity is MainActivity activity && IsAlive(activity)) if (Microsoft.Maui.ApplicationModel.Platform.CurrentActivity is MainActivity activity && IsAlive(activity))
{ {
activity.RunOnUiThread(actionDismiss); activity.RunOnUiThread(actionDismiss);
return Task.CompletedTask; return Task.CompletedTask;
@ -193,7 +192,7 @@ namespace Bit.Droid.Services
string text = null, string okButtonText = null, string cancelButtonText = null, string text = null, string okButtonText = null, string cancelButtonText = null,
bool numericKeyboard = false, bool autofocus = true, bool password = false) bool numericKeyboard = false, bool autofocus = true, bool password = false)
{ {
var activity = (MainActivity)CrossCurrentActivity.Current.Activity; var activity = (MainActivity)Microsoft.Maui.ApplicationModel.Platform.CurrentActivity;
if (activity == null) if (activity == null)
{ {
return Task.FromResult<string>(null); return Task.FromResult<string>(null);
@ -250,7 +249,7 @@ namespace Bit.Droid.Services
public Task<ValidatablePromptResponse?> DisplayValidatablePromptAsync(ValidatablePromptConfig config) public Task<ValidatablePromptResponse?> DisplayValidatablePromptAsync(ValidatablePromptConfig config)
{ {
var activity = (MainActivity)CrossCurrentActivity.Current.Activity; var activity = (MainActivity)Microsoft.Maui.ApplicationModel.Platform.CurrentActivity;
if (activity == null) if (activity == null)
{ {
return Task.FromResult<ValidatablePromptResponse?>(null); return Task.FromResult<ValidatablePromptResponse?>(null);
@ -327,7 +326,7 @@ namespace Bit.Droid.Services
public void RateApp() public void RateApp()
{ {
var activity = (MainActivity)CrossCurrentActivity.Current.Activity; var activity = (MainActivity)Microsoft.Maui.ApplicationModel.Platform.CurrentActivity;
try try
{ {
var rateIntent = RateIntentForUrl("market://details", activity); var rateIntent = RateIntentForUrl("market://details", activity);
@ -360,14 +359,14 @@ namespace Bit.Droid.Services
public bool SupportsNfc() public bool SupportsNfc()
{ {
var activity = (MainActivity)CrossCurrentActivity.Current.Activity; var activity = (MainActivity)Microsoft.Maui.ApplicationModel.Platform.CurrentActivity;
var manager = activity.GetSystemService(Context.NfcService) as NfcManager; var manager = activity.GetSystemService(Context.NfcService) as NfcManager;
return manager.DefaultAdapter?.IsEnabled ?? false; return manager.DefaultAdapter?.IsEnabled ?? false;
} }
public bool SupportsCamera() public bool SupportsCamera()
{ {
var activity = (MainActivity)CrossCurrentActivity.Current.Activity; var activity = (MainActivity)Microsoft.Maui.ApplicationModel.Platform.CurrentActivity;
return activity.PackageManager.HasSystemFeature(PackageManager.FeatureCamera); return activity.PackageManager.HasSystemFeature(PackageManager.FeatureCamera);
} }
@ -383,7 +382,7 @@ namespace Bit.Droid.Services
public Task<string> DisplayAlertAsync(string title, string message, string cancel, params string[] buttons) public Task<string> DisplayAlertAsync(string title, string message, string cancel, params string[] buttons)
{ {
var activity = (MainActivity)CrossCurrentActivity.Current.Activity; var activity = (MainActivity)Microsoft.Maui.ApplicationModel.Platform.CurrentActivity;
if (activity == null) if (activity == null)
{ {
return Task.FromResult<string>(null); return Task.FromResult<string>(null);
@ -464,7 +463,7 @@ namespace Bit.Droid.Services
public void OpenAccessibilityOverlayPermissionSettings() public void OpenAccessibilityOverlayPermissionSettings()
{ {
var activity = (MainActivity)CrossCurrentActivity.Current.Activity; var activity = (MainActivity)Microsoft.Maui.ApplicationModel.Platform.CurrentActivity;
try try
{ {
var intent = new Intent(Settings.ActionManageOverlayPermission); var intent = new Intent(Settings.ActionManageOverlayPermission);
@ -495,7 +494,7 @@ namespace Bit.Droid.Services
{ {
try try
{ {
var activity = (MainActivity)CrossCurrentActivity.Current.Activity; var activity = (MainActivity)Microsoft.Maui.ApplicationModel.Platform.CurrentActivity;
var intent = new Intent(Settings.ActionAccessibilitySettings); var intent = new Intent(Settings.ActionAccessibilitySettings);
activity.StartActivity(intent); activity.StartActivity(intent);
} }
@ -504,7 +503,7 @@ namespace Bit.Droid.Services
public void OpenAutofillSettings() public void OpenAutofillSettings()
{ {
var activity = (MainActivity)CrossCurrentActivity.Current.Activity; var activity = (MainActivity)Microsoft.Maui.ApplicationModel.Platform.CurrentActivity;
try try
{ {
var intent = new Intent(Settings.ActionRequestSetAutofillService); var intent = new Intent(Settings.ActionRequestSetAutofillService);
@ -535,7 +534,7 @@ namespace Bit.Droid.Services
public void CloseMainApp() public void CloseMainApp()
{ {
var activity = (MainActivity)CrossCurrentActivity.Current.Activity; var activity = (MainActivity)Microsoft.Maui.ApplicationModel.Platform.CurrentActivity;
if (activity == null) if (activity == null)
{ {
return; return;
@ -574,7 +573,7 @@ namespace Bit.Droid.Services
public float GetSystemFontSizeScale() public float GetSystemFontSizeScale()
{ {
var activity = CrossCurrentActivity.Current?.Activity as MainActivity; var activity = Microsoft.Maui.ApplicationModel.Platform.CurrentActivity as MainActivity;
return activity?.Resources?.Configuration?.FontScale ?? 1; return activity?.Resources?.Configuration?.FontScale ?? 1;
} }
@ -585,7 +584,7 @@ namespace Bit.Droid.Services
public async Task SetScreenCaptureAllowedAsync() public async Task SetScreenCaptureAllowedAsync()
{ {
var activity = CrossCurrentActivity.Current?.Activity; var activity = Microsoft.Maui.ApplicationModel.Platform.CurrentActivity;
if (await _stateService.GetScreenCaptureAllowedAsync()) if (await _stateService.GetScreenCaptureAllowedAsync())
{ {
activity.RunOnUiThread(() => activity.Window.ClearFlags(WindowManagerFlags.Secure)); activity.RunOnUiThread(() => activity.Window.ClearFlags(WindowManagerFlags.Secure));

View file

@ -13,7 +13,6 @@ using AndroidX.Core.Content;
using Bit.Core.Resources.Localization; using Bit.Core.Resources.Localization;
using Bit.Core; using Bit.Core;
using Bit.Core.Abstractions; using Bit.Core.Abstractions;
using Plugin.CurrentActivity;
using FileProvider = AndroidX.Core.Content.FileProvider; using FileProvider = AndroidX.Core.Content.FileProvider;
namespace Bit.Droid.Services namespace Bit.Droid.Services
@ -43,7 +42,7 @@ namespace Bit.Droid.Services
{ {
try try
{ {
var activity = (MainActivity)CrossCurrentActivity.Current.Activity; var activity = (MainActivity)Microsoft.Maui.ApplicationModel.Platform.CurrentActivity;
var intent = BuildOpenFileIntent(fileData, fileName); var intent = BuildOpenFileIntent(fileData, fileName);
if (intent == null) if (intent == null)
{ {
@ -60,7 +59,7 @@ namespace Bit.Droid.Services
{ {
try try
{ {
var activity = (MainActivity)CrossCurrentActivity.Current.Activity; var activity = (MainActivity)Microsoft.Maui.ApplicationModel.Platform.CurrentActivity;
var intent = BuildOpenFileIntent(new byte[0], string.Concat("opentest_", fileName)); var intent = BuildOpenFileIntent(new byte[0], string.Concat("opentest_", fileName));
if (intent == null) if (intent == null)
{ {
@ -87,7 +86,7 @@ namespace Bit.Droid.Services
return null; return null;
} }
var activity = (MainActivity)CrossCurrentActivity.Current.Activity; var activity = (MainActivity)Microsoft.Maui.ApplicationModel.Platform.CurrentActivity;
var cachePath = activity.CacheDir; var cachePath = activity.CacheDir;
var filePath = Path.Combine(cachePath.Path, fileName); var filePath = Path.Combine(cachePath.Path, fileName);
File.WriteAllBytes(filePath, fileData); File.WriteAllBytes(filePath, fileData);
@ -114,7 +113,7 @@ namespace Bit.Droid.Services
{ {
try try
{ {
var activity = (MainActivity)CrossCurrentActivity.Current.Activity; var activity = (MainActivity)Microsoft.Maui.ApplicationModel.Platform.CurrentActivity;
if (contentUri != null) if (contentUri != null)
{ {
@ -162,7 +161,7 @@ namespace Bit.Droid.Services
{ {
try try
{ {
DeleteDir(CrossCurrentActivity.Current.Activity.CacheDir); DeleteDir(Microsoft.Maui.ApplicationModel.Platform.CurrentActivity?.CacheDir);
await _stateService.SetLastFileCacheClearAsync(DateTime.UtcNow); await _stateService.SetLastFileCacheClearAsync(DateTime.UtcNow);
} }
catch (Exception) { } catch (Exception) { }
@ -170,7 +169,7 @@ namespace Bit.Droid.Services
public Task SelectFileAsync() public Task SelectFileAsync()
{ {
var activity = (MainActivity)CrossCurrentActivity.Current.Activity; var activity = (MainActivity)Microsoft.Maui.ApplicationModel.Platform.CurrentActivity;
var hasStorageWritePermission = !_cameraPermissionsDenied && var hasStorageWritePermission = !_cameraPermissionsDenied &&
HasPermission(Manifest.Permission.WriteExternalStorage); HasPermission(Manifest.Permission.WriteExternalStorage);
var additionalIntents = new List<IParcelable>(); var additionalIntents = new List<IParcelable>();
@ -249,20 +248,30 @@ namespace Bit.Droid.Services
private bool HasPermission(string permission) private bool HasPermission(string permission)
{ {
return ContextCompat.CheckSelfPermission( var activity = Microsoft.Maui.ApplicationModel.Platform.CurrentActivity;
CrossCurrentActivity.Current.Activity, permission) == Permission.Granted; if (activity != null)
{
return ContextCompat.CheckSelfPermission(activity, permission) == Permission.Granted;
}
else
{
return false;
}
} }
private void AskPermission(string permission) private void AskPermission(string permission)
{ {
ActivityCompat.RequestPermissions(CrossCurrentActivity.Current.Activity, new string[] { permission }, var activity = Microsoft.Maui.ApplicationModel.Platform.CurrentActivity;
Core.Constants.SelectFilePermissionRequestCode); if (activity != null)
{
ActivityCompat.RequestPermissions(activity, new string[] { permission }, Core.Constants.SelectFilePermissionRequestCode);
}
} }
private List<IParcelable> GetCameraIntents(Android.Net.Uri outputUri) private List<IParcelable> GetCameraIntents(Android.Net.Uri outputUri)
{ {
var intents = new List<IParcelable>(); var intents = new List<IParcelable>();
var pm = CrossCurrentActivity.Current.Activity.PackageManager; var pm = Microsoft.Maui.ApplicationModel.Platform.CurrentActivity?.PackageManager;
var captureIntent = new Intent(MediaStore.ActionImageCapture); var captureIntent = new Intent(MediaStore.ActionImageCapture);
var listCam = pm.QueryIntentActivities(captureIntent, 0); var listCam = pm.QueryIntentActivities(captureIntent, 0);
foreach (var res in listCam) foreach (var res in listCam)

View file

@ -72,7 +72,6 @@
<Label <Label
Grid.Column="0" Grid.Column="0"
Grid.Row="0" Grid.Row="0"
HorizontalTextAlignment="Start"
LineBreakMode="TailTruncation" LineBreakMode="TailTruncation"
StyleClass="list-title, list-title-platform" StyleClass="list-title, list-title-platform"
Text="{Binding Cipher.Name}" Text="{Binding Cipher.Name}"
@ -81,7 +80,6 @@
Grid.Column="0" Grid.Column="0"
Grid.Row="1" Grid.Row="1"
Grid.ColumnSpan="3" Grid.ColumnSpan="3"
HorizontalTextAlignment="Start"
LineBreakMode="TailTruncation" LineBreakMode="TailTruncation"
StyleClass="list-subtitle, list-subtitle-platform" StyleClass="list-subtitle, list-subtitle-platform"
Text="{Binding Cipher.SubTitle}" Text="{Binding Cipher.SubTitle}"

View file

@ -47,7 +47,6 @@
<PackageReference Include="Portable.BouncyCastle" Version="1.9.0" /> <PackageReference Include="Portable.BouncyCastle" Version="1.9.0" />
</ItemGroup> </ItemGroup>
<ItemGroup Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'android'"> <ItemGroup Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'android'">
<PackageReference Include="Plugin.CurrentActivity" Version="2.1.0.4" />
<PackageReference Include="Xamarin.AndroidX.AutoFill" Version="1.1.0.18" /> <PackageReference Include="Xamarin.AndroidX.AutoFill" Version="1.1.0.18" />
<PackageReference Include="Xamarin.AndroidX.Activity.Ktx" Version="1.7.2.1" /> <PackageReference Include="Xamarin.AndroidX.Activity.Ktx" Version="1.7.2.1" />
</ItemGroup> </ItemGroup>