1
0
mirror of https://github.com/bitwarden/mobile.git synced 2024-11-23 11:45:38 +01:00

cleanup subscriptions when autofilling

This commit is contained in:
Kyle Spearrin 2017-11-21 13:26:06 -05:00
parent bc04211b79
commit 1a9d0576c8
2 changed files with 54 additions and 40 deletions

View File

@ -8,6 +8,7 @@ using Android.OS;
using Android.Views.Accessibility;
using Bit.App.Abstractions;
using XLabs.Ioc;
using Bit.App.Resources;
namespace Bit.Android
{
@ -16,6 +17,8 @@ namespace Bit.Android
[MetaData("android.accessibilityservice", Resource = "@xml/accessibilityservice")]
public class AutofillService : AccessibilityService
{
private NotificationChannel _notificationChannel;
private const int AutoFillNotificationId = 34573;
private const string SystemUiPackage = "com.android.systemui";
private const string BitwardenPackage = "com.x8bit.bitwarden";
@ -362,6 +365,17 @@ namespace Bit.Android
Resource.Color.primary));
}
if(Build.VERSION.SdkInt >= BuildVersionCodes.O)
{
if(_notificationChannel == null)
{
_notificationChannel = new NotificationChannel("bitwarden_autofill_service",
AppResources.BitwardenAutofillService, NotificationImportance.Default);
notificationManager.CreateNotificationChannel(_notificationChannel);
}
builder.SetChannelId(_notificationChannel.Id);
}
if(/*Build.VERSION.SdkInt <= BuildVersionCodes.N && */_appSettings.AutofillPersistNotification)
{
builder.SetPriority(-2);

View File

@ -39,6 +39,7 @@ namespace Bit.Android
private Java.Util.Regex.Pattern _otpPattern = Java.Util.Regex.Pattern.Compile("^.*?([cbdefghijklnrtuv]{32,64})$");
private IDeviceActionService _deviceActionService;
private ISettings _settings;
private AppOptions _appOptions;
protected override void OnCreate(Bundle bundle)
{
@ -78,8 +79,9 @@ namespace Bit.Android
_deviceActionService = Resolver.Resolve<IDeviceActionService>();
_settings = Resolver.Resolve<ISettings>();
_appOptions = GetOptions();
LoadApplication(new App.App(
GetOptions(),
_appOptions,
Resolver.Resolve<IAuthService>(),
Resolver.Resolve<IConnectivity>(),
Resolver.Resolve<IUserDialogs>(),
@ -93,32 +95,34 @@ namespace Bit.Android
Resolver.Resolve<IAppSettingsService>(),
_deviceActionService));
MessagingCenter.Subscribe<Xamarin.Forms.Application>(
Xamarin.Forms.Application.Current, "DismissKeyboard", (sender) =>
if(_appOptions?.Uri == null)
{
DismissKeyboard();
});
MessagingCenter.Subscribe<Xamarin.Forms.Application>(Xamarin.Forms.Application.Current,
"DismissKeyboard", (sender) => DismissKeyboard());
MessagingCenter.Subscribe<Xamarin.Forms.Application>(Xamarin.Forms.Application.Current, "RateApp", (sender) =>
{
RateApp();
});
MessagingCenter.Subscribe<Xamarin.Forms.Application>(Xamarin.Forms.Application.Current,
"RateApp", (sender) => RateApp());
MessagingCenter.Subscribe<Xamarin.Forms.Application>(Xamarin.Forms.Application.Current, "Accessibility", (sender) =>
{
OpenAccessibilitySettings();
});
MessagingCenter.Subscribe<Xamarin.Forms.Application>(Xamarin.Forms.Application.Current,
"Accessibility", (sender) => OpenAccessibilitySettings());
MessagingCenter.Subscribe<Xamarin.Forms.Application, string>(Xamarin.Forms.Application.Current,
"LaunchApp", (sender, args) => LaunchApp(args));
MessagingCenter.Subscribe<Xamarin.Forms.Application, bool>(Xamarin.Forms.Application.Current,
"ListenYubiKeyOTP", (sender, listen) => ListenYubiKey(listen));
}
MessagingCenter.Subscribe<Xamarin.Forms.Application, VaultListPageModel.Cipher>(
Xamarin.Forms.Application.Current, "Autofill", (sender, args) =>
{
ReturnCredentials(args);
});
Xamarin.Forms.Application.Current, "Autofill", (sender, args) => ReturnCredentials(args));
MessagingCenter.Subscribe<Xamarin.Forms.Application>(Xamarin.Forms.Application.Current, "BackgroundApp", (sender) =>
MessagingCenter.Subscribe<Xamarin.Forms.Application>(Xamarin.Forms.Application.Current,
"BackgroundApp", (sender) =>
{
if(Intent.GetBooleanExtra("autofillFramework", false))
{
MessagingCenter.Unsubscribe<Xamarin.Forms.Application>(Xamarin.Forms.Application.Current,
"BackgroundApp");
SetResult(Result.Canceled);
Finish();
}
@ -127,22 +131,18 @@ namespace Bit.Android
MoveTaskToBack(true);
}
});
MessagingCenter.Subscribe<Xamarin.Forms.Application, string>(
Xamarin.Forms.Application.Current, "LaunchApp", (sender, args) =>
{
LaunchApp(args);
});
MessagingCenter.Subscribe<Xamarin.Forms.Application, bool>(
Xamarin.Forms.Application.Current, "ListenYubiKeyOTP", (sender, listen) =>
{
ListenYubiKey(listen);
});
}
private void ReturnCredentials(VaultListPageModel.Cipher cipher)
{
if(_appOptions?.Uri != null)
{
MessagingCenter.Unsubscribe<Xamarin.Forms.Application, VaultListPageModel.Cipher>(
Xamarin.Forms.Application.Current, "Autofill");
MessagingCenter.Unsubscribe<Xamarin.Forms.Application>(Xamarin.Forms.Application.Current,
"BackgroundApp");
}
if(Intent.GetBooleanExtra("autofillFramework", false))
{
if(cipher == null)