1
0
mirror of https://github.com/bitwarden/mobile.git synced 2024-11-27 12:26:31 +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 Android.Views.Accessibility;
using Bit.App.Abstractions; using Bit.App.Abstractions;
using XLabs.Ioc; using XLabs.Ioc;
using Bit.App.Resources;
namespace Bit.Android namespace Bit.Android
{ {
@ -16,6 +17,8 @@ namespace Bit.Android
[MetaData("android.accessibilityservice", Resource = "@xml/accessibilityservice")] [MetaData("android.accessibilityservice", Resource = "@xml/accessibilityservice")]
public class AutofillService : AccessibilityService public class AutofillService : AccessibilityService
{ {
private NotificationChannel _notificationChannel;
private const int AutoFillNotificationId = 34573; private const int AutoFillNotificationId = 34573;
private const string SystemUiPackage = "com.android.systemui"; private const string SystemUiPackage = "com.android.systemui";
private const string BitwardenPackage = "com.x8bit.bitwarden"; private const string BitwardenPackage = "com.x8bit.bitwarden";
@ -362,6 +365,17 @@ namespace Bit.Android
Resource.Color.primary)); 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) if(/*Build.VERSION.SdkInt <= BuildVersionCodes.N && */_appSettings.AutofillPersistNotification)
{ {
builder.SetPriority(-2); 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 Java.Util.Regex.Pattern _otpPattern = Java.Util.Regex.Pattern.Compile("^.*?([cbdefghijklnrtuv]{32,64})$");
private IDeviceActionService _deviceActionService; private IDeviceActionService _deviceActionService;
private ISettings _settings; private ISettings _settings;
private AppOptions _appOptions;
protected override void OnCreate(Bundle bundle) protected override void OnCreate(Bundle bundle)
{ {
@ -78,8 +79,9 @@ namespace Bit.Android
_deviceActionService = Resolver.Resolve<IDeviceActionService>(); _deviceActionService = Resolver.Resolve<IDeviceActionService>();
_settings = Resolver.Resolve<ISettings>(); _settings = Resolver.Resolve<ISettings>();
_appOptions = GetOptions();
LoadApplication(new App.App( LoadApplication(new App.App(
GetOptions(), _appOptions,
Resolver.Resolve<IAuthService>(), Resolver.Resolve<IAuthService>(),
Resolver.Resolve<IConnectivity>(), Resolver.Resolve<IConnectivity>(),
Resolver.Resolve<IUserDialogs>(), Resolver.Resolve<IUserDialogs>(),
@ -93,56 +95,54 @@ namespace Bit.Android
Resolver.Resolve<IAppSettingsService>(), Resolver.Resolve<IAppSettingsService>(),
_deviceActionService)); _deviceActionService));
MessagingCenter.Subscribe<Xamarin.Forms.Application>( if(_appOptions?.Uri == null)
Xamarin.Forms.Application.Current, "DismissKeyboard", (sender) =>
{ {
DismissKeyboard(); MessagingCenter.Subscribe<Xamarin.Forms.Application>(Xamarin.Forms.Application.Current,
}); "DismissKeyboard", (sender) => DismissKeyboard());
MessagingCenter.Subscribe<Xamarin.Forms.Application>(Xamarin.Forms.Application.Current, "RateApp", (sender) => MessagingCenter.Subscribe<Xamarin.Forms.Application>(Xamarin.Forms.Application.Current,
{ "RateApp", (sender) => RateApp());
RateApp();
});
MessagingCenter.Subscribe<Xamarin.Forms.Application>(Xamarin.Forms.Application.Current, "Accessibility", (sender) => MessagingCenter.Subscribe<Xamarin.Forms.Application>(Xamarin.Forms.Application.Current,
{ "Accessibility", (sender) => OpenAccessibilitySettings());
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>( MessagingCenter.Subscribe<Xamarin.Forms.Application, VaultListPageModel.Cipher>(
Xamarin.Forms.Application.Current, "Autofill", (sender, args) => Xamarin.Forms.Application.Current, "Autofill", (sender, args) => ReturnCredentials(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))
{ {
SetResult(Result.Canceled); if(Intent.GetBooleanExtra("autofillFramework", false))
Finish(); {
} MessagingCenter.Unsubscribe<Xamarin.Forms.Application>(Xamarin.Forms.Application.Current,
else "BackgroundApp");
{ SetResult(Result.Canceled);
MoveTaskToBack(true); Finish();
} }
}); else
{
MessagingCenter.Subscribe<Xamarin.Forms.Application, string>( MoveTaskToBack(true);
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) 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(Intent.GetBooleanExtra("autofillFramework", false))
{ {
if(cipher == null) if(cipher == null)